show static method
Future<(DateTime?, DateTimeRange<DateTime> ?, ActionType)?>
show(
- BuildContext context, {
- DateTime? initialDate,
- DateTime? firstDate,
- DateTime? lastDate,
- int selectedTab = 0,
- bool showTabs = true,
- bool showOnlyCustomRange = false,
- DateTimeRange<
DateTime> ? initialDateTimeRange, - String headerText = 'Select month and year',
- bool showAllMonths = false,
- Color? primaryColor,
- Color? unselectedTextColor,
- String? fontFamily,
- TextStyle? tabTextStyle,
- TextStyle? headerTextStyle,
- TextStyle? pickerTextStyle,
- TextStyle? dateTextStyle,
- TextStyle? buttonTextStyle,
- TextStyle? errorTextStyle,
- TextStyle? labelTextStyle,
- int? maxRangeMonths,
- int? maxRangeYears,
- Widget confirmButtonBuilder(
- VoidCallback onConfirm
- void onValidationError(
- BuildContext context,
- String message
Shows the date picker modal as a bottom sheet.
Returns a tuple containing:
DateTime?: The selected date (when monthly selection is used)DateTimeRange?: The selected date range (when custom range is used)ActionType: The action that was taken (confirm, cancel, reset, or dateTimeRange)
Returns null if the modal was dismissed without selection.
Parameters:
context: The build context used to show the modal bottom sheet.initialDate: The initial date to be selected when the picker opens.firstDate: The earliest date that can be selected. Defaults toDateTime(2020)if not provided.lastDate: The latest date that can be selected. Defaults toDateTime.now()if not provided.selectedTab: The selected tab index. Defaults to 0.showTabs: Whether to show tabs for switching between "Monthly" and "Custom" selection modes. Defaults totrue.showOnlyCustomRange: Whether to show only the Custom range picker (without tabs or Monthly picker). Whentrue, only the Custom date range picker is displayed. Defaults tofalse.initialDateTimeRange: The initial date range to be selected when the picker opens.headerText: The header text displayed at the top of the picker modal. Defaults to 'Select month and year'.showAllMonths: Whether to show all 12 months regardless oflastDaterestriction. Whentrue, all months are displayed even if they exceedlastDate. Whenfalse, months are filtered based onlastDate. Defaults tofalse.primaryColor: Primary color for the picker. If null, uses Theme.of(context).colorScheme.primary.unselectedTextColor: Color for unselected text. If null, uses Theme.of(context).textTheme.bodyMedium?.color with opacity.fontFamily: Global font family that applies across all text in the picker. This font family will be merged into all TextStyles.tabTextStyle: Text style for tab labels. If null, uses Theme defaults.headerTextStyle: Text style for header text. If null, uses Theme defaults.pickerTextStyle: Text style for month/year picker text. If null, uses Theme defaults.dateTextStyle: Text style for date field labels and values. If null, uses Theme defaults.buttonTextStyle: Text style for button text. If null, uses Theme defaults.errorTextStyle: Text style for error messages. If null, uses Theme defaults with red color.labelTextStyle: Text style for info/label text. If null, uses Theme defaults.maxRangeMonths: Maximum allowed range in months for custom date range selection. If null andmaxRangeYearsis also null, no limit is applied (unlimited range). IfmaxRangeYearsis provided, this parameter is ignored.maxRangeYears: Maximum allowed range in years for custom date range selection. If provided, takes precedence overmaxRangeMonths. If bothmaxRangeYearsandmaxRangeMonthsare null, no limit is applied (unlimited range).confirmButtonBuilder: Builder for custom confirm button. If provided, this will be used instead of the default button. The builder receives a VoidCallback that should be called when the button is pressed.onValidationError: Callback for showing validation errors. If null, uses a default inline error display.
Implementation
static Future<(DateTime?, DateTimeRange?, ActionType)?> show(
BuildContext context, {
DateTime? initialDate,
DateTime? firstDate,
DateTime? lastDate,
int selectedTab = 0,
bool showTabs = true,
bool showOnlyCustomRange = false,
DateTimeRange? initialDateTimeRange,
String headerText = 'Select month and year',
bool showAllMonths = false,
Color? primaryColor,
Color? unselectedTextColor,
String? fontFamily,
TextStyle? tabTextStyle,
TextStyle? headerTextStyle,
TextStyle? pickerTextStyle,
TextStyle? dateTextStyle,
TextStyle? buttonTextStyle,
TextStyle? errorTextStyle,
TextStyle? labelTextStyle,
int? maxRangeMonths,
int? maxRangeYears,
Widget Function(VoidCallback onConfirm)? confirmButtonBuilder,
void Function(BuildContext context, String message)? onValidationError,
}) async {
return await showModalBottomSheet<(DateTime?, DateTimeRange?, ActionType)?>(
context: context,
isScrollControlled: true,
enableDrag: false,
showDragHandle: true,
builder: (context) => MonthRangePicker(
selectedTab: selectedTab,
initialDate: initialDate,
firstDate: firstDate,
lastDate: lastDate,
initialDateTimeRange: initialDateTimeRange,
showTabs: showTabs,
showOnlyCustomRange: showOnlyCustomRange,
headerText: headerText,
showAllMonths: showAllMonths,
primaryColor: primaryColor,
unselectedTextColor: unselectedTextColor,
fontFamily: fontFamily,
tabTextStyle: tabTextStyle,
headerTextStyle: headerTextStyle,
pickerTextStyle: pickerTextStyle,
dateTextStyle: dateTextStyle,
buttonTextStyle: buttonTextStyle,
errorTextStyle: errorTextStyle,
labelTextStyle: labelTextStyle,
maxRangeMonths: maxRangeMonths,
maxRangeYears: maxRangeYears,
confirmButtonBuilder: confirmButtonBuilder,
onValidationError: onValidationError,
),
);
}