showDateRangeDialog function
- required BuildContext context,
- DateTimeRangePhrase? initialRange,
- Locale? locale,
- RouteSettings? routeSettings,
- TextDirection? textDirection,
- TransitionBuilder? builder,
Shows a dialog containing a Material Design date and time picker with extensive features such as preset ranges, relative ranges, abd custom ranges.
The returned Future resolves to DateTimeRangePhrase that is the range selected by the user when the user confirms the dialog. If the user cancels the dialog, null is returned.
When the date picker is first displayed, it will show the month of
initialRange
, with initialRange
selected.
The firstDate
is the earliest allowable date. The lastDate
is the latest
allowable date. initialRange
must either fall between these dates,
or be equal to one of them. For each of these DateTime parameters, only
their dates are considered. Their time fields are ignored. They must all
be non-null.
An optional selectableDayPredicate
function can be passed in to only allow
certain days for selection. If provided, only the days that
selectableDayPredicate
returns true for will be selectable. For example,
this can be used to only allow weekdays for selection. If provided, it must
return true for initialRange
.
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
(TextDirection.ltr or TextDirection.rtl) for the date picker. It
defaults to the ambient text direction provided by Directionality. If both
locale
and textDirection
are non-null, textDirection
overrides the
direction chosen for the locale
.
The context
, useRootNavigator
and routeSettings
arguments are passed to
showDialog, the documentation for which discusses how it is used. context
and useRootNavigator
must be non-null.
The builder
parameter can be used to wrap the dialog widget
to add inherited widgets like Theme.
This function was modeled from the showDatePicker function.
Implementation
Future<DateTimeRangePhrase?> showDateRangeDialog({
required BuildContext context,
DateTimeRangePhrase? initialRange,
Locale? locale,
bool useRootNavigator = true,
RouteSettings? routeSettings,
ui.TextDirection? textDirection,
TransitionBuilder? builder,
}) async {
assert(debugCheckHasMaterialLocalizations(context));
Widget dialog = _DatePickerDialog(
initialRange: initialRange,
);
if (textDirection != null) {
dialog = Directionality(
textDirection: textDirection,
child: dialog,
);
}
if (locale != null) {
dialog = Localizations.override(
context: context,
locale: locale,
child: dialog,
);
}
return showDialog<DateTimeRangePhrase>(
context: context,
useRootNavigator: useRootNavigator,
routeSettings: routeSettings,
builder: (BuildContext context) {
return builder == null ? dialog : builder(context, dialog);
},
);
}