show static method

Future<(DateTime?, DateTimeRange<DateTime>?, ActionType)?> show(
  1. BuildContext context, {
  2. DateTime? initialDate,
  3. DateTime? firstDate,
  4. DateTime? lastDate,
  5. int selectedTab = 0,
  6. bool showTabs = true,
  7. bool showOnlyCustomRange = false,
  8. DateTimeRange<DateTime>? initialDateTimeRange,
  9. String headerText = 'Select month and year',
  10. bool showAllMonths = false,
  11. Color? primaryColor,
  12. Color? unselectedTextColor,
  13. String? fontFamily,
  14. TextStyle? tabTextStyle,
  15. TextStyle? headerTextStyle,
  16. TextStyle? pickerTextStyle,
  17. TextStyle? dateTextStyle,
  18. TextStyle? buttonTextStyle,
  19. TextStyle? errorTextStyle,
  20. TextStyle? labelTextStyle,
  21. int? maxRangeMonths,
  22. int? maxRangeYears,
  23. Widget confirmButtonBuilder(
    1. VoidCallback onConfirm
    )?,
  24. void onValidationError(
    1. BuildContext context,
    2. 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 to DateTime(2020) if not provided.
  • lastDate: The latest date that can be selected. Defaults to DateTime.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 to true.
  • showOnlyCustomRange: Whether to show only the Custom range picker (without tabs or Monthly picker). When true, only the Custom date range picker is displayed. Defaults to false.
  • 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 of lastDate restriction. When true, all months are displayed even if they exceed lastDate. When false, months are filtered based on lastDate. Defaults to false.
  • 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 and maxRangeYears is also null, no limit is applied (unlimited range). If maxRangeYears is provided, this parameter is ignored.
  • maxRangeYears: Maximum allowed range in years for custom date range selection. If provided, takes precedence over maxRangeMonths. If both maxRangeYears and maxRangeMonths are 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,
    ),
  );
}