formatTimeOfDay method

  1. @override
String formatTimeOfDay(
  1. TimeOfDay timeOfDay, {
  2. bool alwaysUse24HourFormat = false,
})
override

Formats timeOfDay according to the value of timeOfDayFormat.

If alwaysUse24HourFormat is true, formats hour using HourFormat.HH rather than the default for the current locale. This value is usually passed from MediaQueryData.alwaysUse24HourFormat, which has platform- specific behavior.

Implementation

@override
String formatTimeOfDay(TimeOfDay timeOfDay, { bool alwaysUse24HourFormat = false }) {
  // Not using intl.DateFormat for two reasons:
  //
  // - DateFormat supports more formats than our material time picker does,
  //   and we want to be consistent across time picker format and the string
  //   formatting of the time of day.
  // - DateFormat operates on DateTime, which is sensitive to time eras and
  //   time zones, while here we want to format hour and minute within one day
  //   no matter what date the day falls on.
  final String hour = formatHour(timeOfDay, alwaysUse24HourFormat: alwaysUse24HourFormat);
  final String minute = formatMinute(timeOfDay);
  switch (timeOfDayFormat(alwaysUse24HourFormat: alwaysUse24HourFormat)) {
    case TimeOfDayFormat.h_colon_mm_space_a:
      return '$hour:$minute ${_formatDayPeriod(timeOfDay)!}';
    case TimeOfDayFormat.H_colon_mm:
    case TimeOfDayFormat.HH_colon_mm:
      return '$hour:$minute';
    case TimeOfDayFormat.HH_dot_mm:
      return '$hour.$minute';
    case TimeOfDayFormat.a_space_h_colon_mm:
      return '${_formatDayPeriod(timeOfDay)!} $hour:$minute';
    case TimeOfDayFormat.frenchCanadian:
      return '$hour h $minute';
  }
}