MonthPicker constructor

MonthPicker({
  1. Key? key,
  2. required DateTime minDate,
  3. required DateTime maxDate,
  4. DateTime? initialDate,
  5. DateTime? currentDate,
  6. DateTime? selectedDate,
  7. TextStyle? enabledCellsTextStyle,
  8. BoxDecoration enabledCellsDecoration = const BoxDecoration(),
  9. TextStyle? disabledCellsTextStyle,
  10. BoxDecoration disabledCellsDecoration = const BoxDecoration(),
  11. TextStyle? currentDateTextStyle,
  12. BoxDecoration? currentDateDecoration,
  13. TextStyle? selectedCellTextStyle,
  14. BoxDecoration? selectedCellDecoration,
  15. VoidCallback? onLeadingDateTap,
  16. ValueChanged<DateTime>? onDateSelected,
  17. TextStyle? leadingDateTextStyle,
  18. Color? slidersColor,
  19. double? slidersSize,
  20. Color? highlightColor,
  21. Color? splashColor,
  22. double? splashRadius,
  23. bool centerLeadingDate = false,
  24. String? previousPageSemanticLabel = 'Previous Month',
  25. String? nextPageSemanticLabel = 'Next Month',
})

Creates a month picker.

It will display a grid of months for the initialDate's year. If initialDate is null, DateTime.now() will be used. If DateTime.now() does not fall within the valid range of minDate and maxDate, it will fall back to the nearest valid date from DateTime.now(), selecting the maxDate if DateTime.now() is after the valid range, or minDate if before.

The month indicated by selectedDate will be selected if provided.

The optional onDateSelected callback will be called if provided when a date is selected.

The minDate is the earliest allowable date. The maxDate is the latest allowable date. initialDate and selectedDate must either fall between these dates, or be equal to one of them.

The currentDate represents the current day (i.e. today). This date will be highlighted in the day grid. If null, the date of DateTime.now() will be used.

For each of these DateTime parameters, only their year & month are considered. Their time & day fields are ignored.

Implementation

MonthPicker({
  super.key,
  required this.minDate,
  required this.maxDate,
  this.initialDate,
  this.currentDate,
  this.selectedDate,
  this.enabledCellsTextStyle,
  this.enabledCellsDecoration = const BoxDecoration(),
  this.disabledCellsTextStyle,
  this.disabledCellsDecoration = const BoxDecoration(),
  this.currentDateTextStyle,
  this.currentDateDecoration,
  this.selectedCellTextStyle,
  this.selectedCellDecoration,
  this.onLeadingDateTap,
  this.onDateSelected,
  this.leadingDateTextStyle,
  this.slidersColor,
  this.slidersSize,
  this.highlightColor,
  this.splashColor,
  this.splashRadius,
  this.centerLeadingDate = false,
  this.previousPageSemanticLabel = 'Previous Month',
  this.nextPageSemanticLabel = 'Next Month',
}) {
  assert(!minDate.isAfter(maxDate), "minDate can't be after maxDate");

  assert(
    () {
      if (initialDate == null) return true;
      final init = DateUtilsX.monthOnly(initialDate!);

      final min = DateUtilsX.monthOnly(minDate);

      return init.isAfter(min) || init.isAtSameMomentAs(min);
    }(),
    'initialDate $initialDate must be on or after minDate $minDate.',
  );
  assert(
    () {
      if (initialDate == null) return true;
      final init = DateUtilsX.monthOnly(initialDate!);

      final max = DateUtilsX.monthOnly(maxDate);
      return init.isBefore(max) || init.isAtSameMomentAs(max);
    }(),
    'initialDate $initialDate must be on or before maxDate $maxDate.',
  );
}