showDatePicker static method

void showDatePicker(
  1. BuildContext context, {
  2. bool isDismissible = true,
  3. DateTime? minDateTime,
  4. DateTime? maxDateTime,
  5. bool isLimitTimeRange = true,
  6. DateTime? initialStartDateTime,
  7. DateTime? initialEndDateTime,
  8. String? dateFormat,
  9. int minuteDivider = 1,
  10. DateTimePickerLocale locale = datetimePickerLocaleDefault,
  11. BrnDateTimeRangePickerMode pickerMode = BrnDateTimeRangePickerMode.date,
  12. PickerTitleConfig pickerTitleConfig = PickerTitleConfig.Default,
  13. DateVoidCallback? onCancel,
  14. DateVoidCallback? onClose,
  15. DateRangeValueCallback? onChange,
  16. DateRangeValueCallback? onConfirm,
  17. PickerConfig? themeData,
})

isDismissiblebool点击背景是否自动消失 minDateTime: DateTime 可选的最小时间 maxDateTime: DateTime 可选的最大时间 isLimitTimeRange: bool 是否显示开始时间必须小于等于结束时间,默认为 true,仅在 BrnDateTimeRangePickerMode 为 time 时生效 initialDateTime: DateTime 初始化选中时间 dateFormat: String 时间展示格式,如:yyyy 年 MM 月 dd 日 minuteDivider:int 分钟展示间隔,默认值为 1 locale: DateTimePickerLocale internationalization pickerMode: BrnDateTimeRangePickerMode 展示的 mode: date(DatePicker)、time(TimePicker) onCancel: DateVoidCallback 取消回调 onClose: DateVoidCallback 关闭回调 onChange: DateValueCallback 时间变化回调 onConfirm: DateValueCallback 点击确认的回调 pickerTitleConfig: BrnPickerTitleConfig Picker title 配置 themeData: BrnPickerConfig 主题配置

Implementation

static void showDatePicker(
  BuildContext context, {
  bool isDismissible = true,
  DateTime? minDateTime,
  DateTime? maxDateTime,
  bool isLimitTimeRange = true,
  DateTime? initialStartDateTime,
  DateTime? initialEndDateTime,
  String? dateFormat,
  int minuteDivider = 1,
  DateTimePickerLocale locale = datetimePickerLocaleDefault,
  BrnDateTimeRangePickerMode pickerMode = BrnDateTimeRangePickerMode.date,
  PickerTitleConfig pickerTitleConfig = PickerTitleConfig.Default,
  DateVoidCallback? onCancel,
  DateVoidCallback? onClose,
  DateRangeValueCallback? onChange,
  DateRangeValueCallback? onConfirm,
  PickerConfig? themeData,
}) {
  // handle the range of datetime
  minDateTime ??= DateTime.parse(datePickerMinDatetime);
  maxDateTime ??= DateTime.parse(datePickerMaxDatetime);

  // handle initial DateTime
  initialStartDateTime ??= DateTime.now();

  // Set value of date format
  dateFormat =
      DateTimeFormatter.generateDateRangePickerFormat(dateFormat, pickerMode);

  Navigator.push(
    context,
    _DatePickerRoute(
      minDateTime: minDateTime,
      maxDateTime: maxDateTime,
      isLimitTimeRange: isLimitTimeRange,
      initialStartDateTime: initialStartDateTime,
      initialEndDateTime: initialEndDateTime,
      dateFormat: dateFormat,
      minuteDivider: minuteDivider,
      pickerMode: pickerMode,
      pickerTitleConfig: pickerTitleConfig,
      onCancel: onCancel,
      onChange: onChange,
      onConfirm: onConfirm,
      isDismissible: isDismissible,
      barrierLabel:
          MaterialLocalizations.of(context).modalBarrierDismissLabel,
      themeData: themeData,
    ),
  ).whenComplete(onClose ?? () {});
}