import 'package:flutter/material.dart'; extension TimeOfDayExtension on TimeOfDay { /// Adds the given offset, carrying minutes into hours. /// /// Without the carry, adding a minute-based step (e.g. 45) would leave the /// hour untouched and produce values like "8:90", which makes [isBefore] /// loops run forever. The hour is intentionally NOT wrapped at 24 so that /// comparisons against an end-of-day bound still terminate. TimeOfDay add({int hour = 0, int minute = 0}) { final totalMinutes = (this.hour + hour) * 60 + this.minute + minute; return TimeOfDay(hour: totalMinutes ~/ 60, minute: totalMinutes % 60); } int compareTo(TimeOfDay other) { if (hour < other.hour) return -1; if (hour > other.hour) return 1; if (minute < other.minute) return -1; if (minute > other.minute) return 1; return 0; } bool isBefore(TimeOfDay other) { return compareTo(other) == -1; } }