showMaterialDatePicker function
Future<NepaliDateTime?>
showMaterialDatePicker({
- required BuildContext context,
- required NepaliDateTime initialDate,
- required NepaliDateTime firstDate,
- required NepaliDateTime lastDate,
- NepaliDateTime? currentDate,
- DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
- SelectableDayPredicate? selectableDayPredicate,
- String? helpText,
- String? cancelText,
- String? confirmText,
- Locale? locale,
- RouteSettings? routeSettings,
- TextDirection? textDirection,
- TransitionBuilder? builder,
- DatePickerMode initialDatePickerMode = DatePickerMode.day,
- String? errorFormatText,
- String? errorInvalidText,
- String? fieldHintText,
- String? fieldLabelText,
Displays a Material-style date picker dialog.
This function shows a dialog that allows the user to select a date using a Nepali calendar. It supports both calendar and input modes for date selection.
Parameters:
context
: The build context to display the dialog.initialDate
: The initially selected date in the dialog.firstDate
: The earliest selectable date.lastDate
: The latest selectable date.currentDate
: The current date, defaults to today if not provided.
Returns:
A Future that resolves to the selected NepaliDateTime, or null
if the dialog is dismissed.
Implementation
Future<NepaliDateTime?> showMaterialDatePicker({
required BuildContext context,
required NepaliDateTime initialDate,
required NepaliDateTime firstDate,
required NepaliDateTime lastDate,
NepaliDateTime? currentDate,
DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
common.SelectableDayPredicate? selectableDayPredicate,
String? helpText,
String? cancelText,
String? confirmText,
Locale? locale,
bool useRootNavigator = true,
RouteSettings? routeSettings,
TextDirection? textDirection,
TransitionBuilder? builder,
DatePickerMode initialDatePickerMode = DatePickerMode.day,
String? errorFormatText,
String? errorInvalidText,
String? fieldHintText,
String? fieldLabelText,
}) async {
initialDate = utils.dateOnly(initialDate);
firstDate = utils.dateOnly(firstDate);
lastDate = utils.dateOnly(lastDate);
assert(!lastDate.isBefore(firstDate),
'lastDate $lastDate must be on or after firstDate $firstDate.');
assert(!initialDate.isBefore(firstDate),
'initialDate $initialDate must be on or after firstDate $firstDate.');
assert(!initialDate.isAfter(lastDate),
'initialDate $initialDate must be on or before lastDate $lastDate.');
assert(selectableDayPredicate == null || selectableDayPredicate(initialDate),
'Provided initialDate $initialDate must satisfy provided selectableDayPredicate.');
assert(debugCheckHasMaterialLocalizations(context));
Widget dialog = _DatePickerDialog(
initialDate: initialDate,
firstDate: firstDate,
lastDate: lastDate,
currentDate: currentDate,
initialEntryMode: initialEntryMode,
selectableDayPredicate: selectableDayPredicate,
helpText: helpText,
cancelText: cancelText,
confirmText: confirmText,
initialCalendarMode: initialDatePickerMode,
errorFormatText: errorFormatText,
errorInvalidText: errorInvalidText,
fieldHintText: fieldHintText,
fieldLabelText: fieldLabelText,
);
if (textDirection != null) {
dialog = Directionality(
textDirection: textDirection,
child: dialog,
);
}
if (locale != null) {
dialog = Localizations.override(
context: context,
locale: locale,
child: dialog,
);
}
return showDialog<NepaliDateTime>(
context: context,
useRootNavigator: useRootNavigator,
routeSettings: routeSettings,
builder: (BuildContext context) {
return builder == null ? dialog : builder(context, dialog);
},
);
}