showSyncDatePicker function
dynamic
showSyncDatePicker({
- DateTime? initialDate,
- required DateTime firstDate,
- required DateTime lastDate,
- DateTime? currentDate,
- DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
- SelectableDayPredicate? selectableDayPredicate,
- String? helpText,
- String? cancelText,
- String? confirmText,
- Locale? locale,
- bool barrierDismissible = true,
- Color? barrierColor,
- String? barrierLabel,
- RouteSettings? routeSettings,
- TextDirection? textDirection,
- TransitionBuilder? builder,
- DatePickerMode initialDatePickerMode = DatePickerMode.day,
- String? errorFormatText,
- String? errorInvalidText,
- String? fieldHintText,
- String? fieldLabelText,
- TextInputType? keyboardType,
- Offset? anchorPoint,
- ValueChanged<
DatePickerEntryMode> ? onDatePickerModeChange, - Icon? switchToInputEntryModeIcon,
- Icon? switchToCalendarEntryModeIcon,
Shows a date picker using showDatePicker without requiring a BuildContext.
This function is useful for showing date pickers from anywhere in the app, even outside the widget tree.
Example:
showSyncDatePicker(
initialDate: DateTime.now(),
firstDate: DateTime(2022),
lastDate: DateTime(2025),
);
Implementation
showSyncDatePicker({
DateTime? initialDate,
required DateTime firstDate,
required DateTime lastDate,
DateTime? currentDate,
DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
SelectableDayPredicate? selectableDayPredicate,
String? helpText,
String? cancelText,
String? confirmText,
Locale? locale,
bool barrierDismissible = true,
Color? barrierColor,
String? barrierLabel,
bool useRootNavigator = true,
RouteSettings? routeSettings,
TextDirection? textDirection,
TransitionBuilder? builder,
DatePickerMode initialDatePickerMode = DatePickerMode.day,
String? errorFormatText,
String? errorInvalidText,
String? fieldHintText,
String? fieldLabelText,
TextInputType? keyboardType,
Offset? anchorPoint,
final ValueChanged<DatePickerEntryMode>? onDatePickerModeChange,
final Icon? switchToInputEntryModeIcon,
final Icon? switchToCalendarEntryModeIcon,
}) {
initialDate = initialDate == null ? null : DateUtils.dateOnly(initialDate);
firstDate = DateUtils.dateOnly(firstDate);
lastDate = DateUtils.dateOnly(lastDate);
assert(
!lastDate.isBefore(firstDate),
'lastDate $lastDate must be on or after firstDate $firstDate.',
);
assert(
initialDate == null || !initialDate.isBefore(firstDate),
'initialDate $initialDate must be on or after firstDate $firstDate.',
);
assert(
initialDate == null || !initialDate.isAfter(lastDate),
'initialDate $initialDate must be on or before lastDate $lastDate.',
);
assert(
selectableDayPredicate == null ||
initialDate == null ||
selectableDayPredicate(initialDate),
'Provided initialDate $initialDate must satisfy provided selectableDayPredicate.',
);
showDatePicker(
context: Utils.navigatorKey.currentContext!,
firstDate: firstDate,
lastDate: lastDate);
}