showDatePicker static method
void
showDatePicker(
- BuildContext context, {
- bool? canBarrierDismissible,
- DateTime? minDateTime,
- DateTime? maxDateTime,
- DateTime? initialDateTime,
- String? dateFormat,
- int minuteDivider = 1,
- DateTimePickerMode pickerMode = DateTimePickerMode.date,
- PickerTitleConfig pickerTitleConfig = PickerTitleConfig.Default,
- DateVoidCallback? onCancel,
- DateVoidCallback? onClose,
- DateValueCallback? onChange,
- DateValueCallback? onConfirm,
- PickerConfig? themeData,
Display date picker in bottom sheet.
context: BuildContext
minDateTime: DateTime minimum date time
maxDateTime: DateTime maximum date time
initialDateTime: DateTime initial date time for selected
dateFormat: String date format pattern
locale: DateTimePickerLocale internationalization
pickerMode: BrnDateTimePickerMode
display mode: date(DatePicker)、time(TimePicker)、datetime(DateTimePicker)
pickerTheme: BrnPickerTitleConfig
the theme of date time picker
onCancel: DateVoidCallback pressed title cancel widget event
onClose: DateVoidCallback date picker closed event
onChange: DateValueCallback selected date time changed event
onConfirm: DateValueCallback pressed title confirm widget event
Implementation
static void showDatePicker(
BuildContext context, {
/// If rootNavigator is set to true, the state from the furthest instance of this class is given instead.
/// Useful for pushing contents above all subsequent instances of [Navigator].
bool rootNavigator = false,
/// 点击弹框外部区域能否消失
bool? canBarrierDismissible,
/// 能滚动到的最小日期
DateTime? minDateTime,
/// 能滚动到的最大日期
DateTime? maxDateTime,
/// 初始选择的时间。默认当前时间
DateTime? initialDateTime,
/// 时间格式化的格式
String? dateFormat,
/// 分钟间切换的差值
int minuteDivider = 1,
/// 时间选择组件显示的时间类型
DateTimePickerMode pickerMode = DateTimePickerMode.date,
/// 时间选择组件的主题样式
PickerTitleConfig pickerTitleConfig = PickerTitleConfig.Default,
/// 点击【取消】回调给调用方的回调事件
DateVoidCallback? onCancel,
/// 弹框点击外围消失的回调事件
DateVoidCallback? onClose,
/// 时间滚动选择时候的回调事件
DateValueCallback? onChange,
/// 点击【完成】回调给调用方的数据
DateValueCallback? onConfirm,
PickerConfig? themeData,
}) {
// handle the range of datetime
minDateTime ??= DateTime.parse(datePickerMinDatetime);
maxDateTime ??= DateTime.parse(datePickerMaxDatetime);
// handle initial DateTime
initialDateTime ??= DateTime.now();
// Set value of date format
dateFormat = DateTimeFormatter.generateDateFormat(dateFormat, pickerMode);
Navigator.of(context, rootNavigator: rootNavigator)
.push(
_DatePickerRoute(
canBarrierDismissible: canBarrierDismissible,
minDateTime: minDateTime,
maxDateTime: maxDateTime,
initialDateTime: initialDateTime,
dateFormat: dateFormat,
minuteDivider: minuteDivider,
pickerMode: pickerMode,
pickerTitleConfig: pickerTitleConfig,
onCancel: onCancel,
onChange: onChange,
onConfirm: onConfirm,
theme: Theme.of(context),
barrierLabel:
MaterialLocalizations.of(context).modalBarrierDismissLabel,
themeData: themeData,
),
)
.whenComplete(onClose ?? () {});
}