showCustomTimePicker function
Future<TimeOfDay?>
showCustomTimePicker({
- required BuildContext context,
- TimePickerType type = TimePickerType.spin,
- TimeOfDay? initialTime,
- bool use24Hour = true,
- int minuteInterval = 1,
- CustomDatePickerThemeData theme = CustomDatePickerThemeData.minimal,
Opens a spin or dropdown time picker. The result is one TimeOfDay.
TimePickerType.input throws ArgumentError. Type the time with CustomTimeField instead.
Implementation
Future<TimeOfDay?> showCustomTimePicker({
required BuildContext context,
TimePickerType type = TimePickerType.spin,
TimeOfDay? initialTime,
bool use24Hour = true,
int minuteInterval = 1,
CustomDatePickerThemeData theme = CustomDatePickerThemeData.minimal,
}) {
if (type == TimePickerType.input) {
throw ArgumentError('$type is not opened with showCustomTimePicker.');
}
final initial = normalizeTime(
initialTime ?? TimeOfDay.now(),
minuteInterval: minuteInterval,
);
return showModalBottomSheet<TimeOfDay>(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (context) {
return CustomDatePickerTheme(
data: theme,
child: switch (type) {
TimePickerType.spin => SpinTimePicker(
initialTime: initial,
use24Hour: use24Hour,
minuteInterval: minuteInterval,
),
TimePickerType.dropdown => DropdownTimePicker(
initialTime: initial,
use24Hour: use24Hour,
minuteInterval: minuteInterval,
),
TimePickerType.input => const SizedBox.shrink(),
},
);
},
);
}