to12HourString method

String to12HourString({
  1. bool includeSpace = true,
})

Returns "2:30 PM" style – 12-hour with AM/PM (you choose the style)

Implementation

String to12HourString({bool includeSpace = true}) {
  final h = hour == 0
      ? 12
      : hour > 12
      ? hour - 12
      : hour;
  final period = hour >= 12 ? 'PM' : 'AM';
  final space = includeSpace ? ' ' : '';
  return '$h:${minute.toString().padLeft(2, '0')}$space$period';
}