parseTime method
Implementation
TimeOfDay? parseTime(String time) {
try {
final format = RegExp(r'^(\d{1,2}):(\d{2})\s?(AM|PM)$', caseSensitive: false);
final match = format.firstMatch(time);
if (match != null) {
final hour = int.parse(match.group(1)!);
final minute = int.parse(match.group(2)!);
final period = match.group(3)!.toUpperCase();
return TimeOfDay(
hour: (period == 'PM' && hour != 12
? hour + 12
: hour == 12
? 0
: hour),
minute: minute,
);
}
} catch (_) {}
return null; // Return null if parsing fails
}