formatHour method Null safety

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

Formats TimeOfDay.hour in the given time of day according to the value of timeOfDayFormat.

If alwaysUse24HourFormat is true, formats hour using HourFormat.HH rather than the default for the current locale.


String formatHour(TimeOfDay timeOfDay, { bool alwaysUse24HourFormat = false }) {
  final TimeOfDayFormat format = timeOfDayFormat(alwaysUse24HourFormat: alwaysUse24HourFormat);
  switch (format) {
    case TimeOfDayFormat.h_colon_mm_space_a:
      return formatDecimal(timeOfDay.hourOfPeriod == 0 ? 12 : timeOfDay.hourOfPeriod);
    case TimeOfDayFormat.HH_colon_mm:
      return _formatTwoDigitZeroPad(timeOfDay.hour);
      throw AssertionError('$runtimeType does not support $format.');