showMonthYearPicker function
Future<DateTime?>
showMonthYearPicker({
- required BuildContext context,
- required DateTime initialDate,
- required DateTime firstDate,
- required DateTime lastDate,
- SelectableMonthYearPredicate? selectableMonthYearPredicate,
- Locale? locale,
- RouteSettings? routeSettings,
- TextDirection? textDirection,
- TransitionBuilder? builder,
- MonthYearPickerMode initialMonthYearPickerMode = MonthYearPickerMode.month,
Displays month year picker dialog.
initialDate
is the initially selected month.
firstDate
is the lower bound for month selection.
lastDate
is the upper bound for month selection.
Implementation
Future<DateTime?> showMonthYearPicker({
required BuildContext context,
required DateTime initialDate,
required DateTime firstDate,
required DateTime lastDate,
SelectableMonthYearPredicate? selectableMonthYearPredicate,
Locale? locale,
bool useRootNavigator = true,
RouteSettings? routeSettings,
TextDirection? textDirection,
TransitionBuilder? builder,
MonthYearPickerMode initialMonthYearPickerMode = MonthYearPickerMode.month,
}) async {
initialDate = monthYearOnly(initialDate);
firstDate = monthYearOnly(firstDate);
lastDate = monthYearOnly(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(debugCheckHasMaterialLocalizations(context));
assert(debugCheckHasMonthYearPickerLocalizations(context));
assert(debugCheckHasDirectionality(context));
Widget dialog = MonthYearPickerDialog(
initialDate: initialDate,
firstDate: firstDate,
lastDate: lastDate,
initialMonthYearPickerMode: initialMonthYearPickerMode,
selectableMonthYearPredicate: selectableMonthYearPredicate,
);
if (textDirection != null) {
dialog = Directionality(
textDirection: textDirection,
child: dialog,
);
}
if (locale != null) {
dialog = Localizations.override(
context: context,
locale: locale,
child: dialog,
);
}
return await showDialog<DateTime>(
context: context,
useRootNavigator: useRootNavigator,
routeSettings: routeSettings,
builder: (context) => builder == null ? dialog : builder(context, dialog),
);
}