formatTimeOfDay static method
Implementation
static String formatTimeOfDay(TimeOfDay? timeOfDay, {bool formatTo12Hr = true}) {
if (timeOfDay == null) return '';
String addLeadingZeroIfNeeded(int value) {
if (value < 10) {
return '0$value';
}
return value.toString();
}
int hr = formatTo12Hr ? timeOfDay.hour % 12 : timeOfDay.hour;
final String hourLabel = addLeadingZeroIfNeeded(hr);
final String minuteLabel = addLeadingZeroIfNeeded(timeOfDay.minute);
String suffix = formatTo12Hr
? (timeOfDay.hour > 11 ? ' PM' : ' AM')
: '';
return '$hourLabel:$minuteLabel$suffix';
}