Dart/Flutter How to compare two TimeOfDay times?

Jesse picture Jesse · Feb 11, 2019 · Viewed 16.1k times · Source

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?

Answer

Lucas picture Lucas · Feb 12, 2019

Convert it to a double then compare.

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