showCupertinoTimePicker function
Future<TimeOfDay?>
showCupertinoTimePicker(
- BuildContext context, {
- String? titleText,
- TimeOfDay? initialTime,
- TimeOfDay? minimumTime,
- TimeOfDay? maximumTime,
- Color? backgroundColor,
- double? itemExtent,
- bool? useMagnifier,
- double? magnification,
- double? diameterRatio,
- TextStyle? textStyle,
- TextStyle? unselectedTextStyle,
- Color? unselectedColor,
- double? squeeze,
显示 iOS 风格的事件选择器
Implementation
Future<TimeOfDay?> showCupertinoTimePicker(
BuildContext context, {
String? titleText,
TimeOfDay? initialTime,
TimeOfDay? minimumTime,
TimeOfDay? maximumTime,
Color? backgroundColor,
double? itemExtent,
bool? useMagnifier,
double? magnification,
double? diameterRatio,
TextStyle? textStyle,
TextStyle? unselectedTextStyle,
Color? unselectedColor,
double? squeeze,
}) async {
minimumTime ??= const TimeOfDay(hour: 0, minute: 0);
maximumTime ??= const TimeOfDay(hour: 23, minute: 59);
TimeOfDay result = initialTime ?? TimeOfDay.now();
return await showDefaultBottomSheet<TimeOfDay>(
context,
title: titleText ?? TxLocalizations.of(context).timePickerTitle,
elevation: 0,
backgroundColor: Theme.of(context).colorScheme.surface,
contentBuilder: (context) => TxCupertinoTimePicker(
initialTime: result.toDateTime(),
minimumTime: minimumTime,
maximumTime: maximumTime,
backgroundColor: backgroundColor,
onTimeChanged: (DateTime time) => result = TimeOfDay.fromDateTime(time),
use24hFormat: true,
itemExtent: itemExtent,
useMagnifier: useMagnifier,
magnification: magnification,
diameterRatio: diameterRatio,
textStyle: textStyle,
unselectedColor: unselectedColor,
unselectedTextStyle: unselectedTextStyle,
),
onConfirm: () => Navigator.pop(context, result),
);
}