showDatePicker function

Future<List<DateTime>> showDatePicker(
  1. {@required BuildContext context,
  2. @required DateTime initialFirstDate,
  3. @required DateTime initialLastDate,
  4. @required DateTime firstDate,
  5. @required DateTime lastDate,
  6. SelectableDayPredicate selectableDayPredicate,
  7. DatePickerMode initialDatePickerMode =,
  8. Locale locale,
  9. TextDirection textDirection}

Shows a dialog containing a material design date picker.

The returned Future resolves to the date selected by the user when the user closes the dialog. If the user cancels the dialog, null is returned.

An optional selectableDayPredicate function can be passed in to customize the days to enable for selection. If provided, only the days that selectableDayPredicate returned true for will be selectable.

An optional initialDatePickerMode argument can be used to display the date picker initially in the year or month+day picker mode. It defaults to month+day, and must not be null.

An optional locale argument can be used to set the locale for the date picker. It defaults to the ambient locale provided by Localizations.

An optional textDirection argument can be used to set the text direction (RTL or LTR) for the date picker. It defaults to the ambient text direction provided by Directionality. If both locale and textDirection are not null, textDirection overrides the direction chosen for the locale.

The context argument is passed to showDialog, the documentation for which discusses how it is used.

See also:


Future<List<DateTime>> showDatePicker({
  @required BuildContext context,
  @required DateTime initialFirstDate,
  @required DateTime initialLastDate,
  @required DateTime firstDate,
  @required DateTime lastDate,
  SelectableDayPredicate selectableDayPredicate,
  DatePickerMode initialDatePickerMode =,
  Locale locale,
  TextDirection textDirection,
}) async {
      'initialDate must be on or after firstDate');
      'initialDate must be on or before lastDate');
      'initialFirstDate must be on or before initialLastDate');
      !firstDate.isAfter(lastDate), 'lastDate must be on or after firstDate');
      selectableDayPredicate == null ||
          selectableDayPredicate(initialFirstDate) ||
      'Provided initialDate must satisfy provided selectableDayPredicate');
      initialDatePickerMode != null, 'initialDatePickerMode must not be null');

  Widget child = new _DatePickerDialog(
    initialFirstDate: initialFirstDate,
    initialLastDate: initialLastDate,
    firstDate: firstDate,
    lastDate: lastDate,
    selectableDayPredicate: selectableDayPredicate,
    initialDatePickerMode: initialDatePickerMode,

  if (textDirection != null) {
    child = new Directionality(
      textDirection: textDirection,
      child: child,

  if (locale != null) {
    child = new Localizations.override(
      context: context,
      locale: locale,
      child: child,

  return await showDialog<List<DateTime>>(
    context: context,
    builder: (BuildContext context) => child,