showMaterialDatePicker function

Future<NepaliDateTime?> showMaterialDatePicker({
  1. required BuildContext context,
  2. required NepaliDateTime initialDate,
  3. required NepaliDateTime firstDate,
  4. required NepaliDateTime lastDate,
  5. NepaliDateTime? currentDate,
  6. DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
  7. SelectableDayPredicate? selectableDayPredicate,
  8. String? helpText,
  9. String? cancelText,
  10. String? confirmText,
  11. Locale? locale,
  12. bool useRootNavigator = true,
  13. RouteSettings? routeSettings,
  14. TextDirection? textDirection,
  15. TransitionBuilder? builder,
  16. DatePickerMode initialDatePickerMode = DatePickerMode.day,
  17. String? errorFormatText,
  18. String? errorInvalidText,
  19. String? fieldHintText,
  20. 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);
    },
  );
}