viewToModelValue method

  1. @override
TimeOfDay? viewToModelValue(
  1. String? viewValue
)
override

Returns the value that must be supplied to the control.

Converts value from UI data type to control data type.

Implementation

@override
TimeOfDay? viewToModelValue(String? viewValue) {
  if (viewValue == null) {
    return null;
  }

  final parts = viewValue.split(':');
  if (parts.length != 2) {
    return null;
  }

  return TimeOfDay(
    hour: int.parse(parts[0].trim()),
    minute: int.parse(parts[1].trim()),
  );
}