datetimedartfluttertimeofday

Dart/Flutter How to compare two TimeOfDay times?


TimeOfDay documentation has no comparison operator and primitive comparison does not work. My only solution that I can thinking of right now is to convert TimeOfDay to DateTime and use DateTime's difference method.

Does anyone have a better solution?


Solution

  • Convert it to a double then compare.

    double toDouble(TimeOfDay myTime) => myTime.hour + myTime.minute/60.0