showCupertinoTimePicker function

Future<TimeOfDay?> showCupertinoTimePicker(
  1. BuildContext context, {
  2. String? titleText,
  3. TimeOfDay? initialTime,
  4. TimeOfDay? minimumTime,
  5. TimeOfDay? maximumTime,
  6. Color? backgroundColor,
  7. double? itemExtent,
  8. bool? useMagnifier,
  9. double? magnification,
  10. double? diameterRatio,
  11. TextStyle? textStyle,
  12. TextStyle? unselectedTextStyle,
  13. Color? unselectedColor,
  14. 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),
  );
}