month_picker_selection.dart 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import 'utils.dart';
  2. /// Base class for month based pickers selection.
  3. abstract class MonthPickerSelection {
  4. /// If this is before [dateTime].
  5. bool isBefore(DateTime dateTime);
  6. /// If this is after [dateTime].
  7. bool isAfter(DateTime dateTime);
  8. /// Returns earliest [DateTime] in this selection.
  9. DateTime get earliest;
  10. /// Returns latest [DateTime] in this selection.
  11. DateTime get latest;
  12. /// If this selection is empty.
  13. bool get isEmpty;
  14. /// If this selection is not empty.
  15. bool get isNotEmpty;
  16. /// Constructor to allow children to have constant constructor.
  17. const MonthPickerSelection();
  18. }
  19. /// Selection with only one selected month.
  20. ///
  21. /// See also:
  22. /// * [MonthPickerMultiSelection] - selection with one or many single dates.
  23. class MonthPickerSingleSelection extends MonthPickerSelection {
  24. /// Selected date.
  25. final DateTime selectedDate;
  26. /// Creates selection with only one selected date.
  27. const MonthPickerSingleSelection(this.selectedDate);
  28. @override
  29. bool isAfter(DateTime dateTime) => selectedDate.isAfter(dateTime);
  30. @override
  31. bool isBefore(DateTime dateTime) => selectedDate.isBefore(dateTime);
  32. @override
  33. DateTime get earliest => selectedDate;
  34. @override
  35. DateTime get latest => selectedDate;
  36. @override
  37. bool get isEmpty => false;
  38. @override
  39. bool get isNotEmpty => true;
  40. }
  41. /// Selection with one or many single months.
  42. ///
  43. /// See also:
  44. /// * [MonthPickerSingleSelection] - selection with only one selected date.
  45. class MonthPickerMultiSelection extends MonthPickerSelection {
  46. /// List of the selected dates.
  47. final List<DateTime> selectedDates;
  48. /// Selection with one or many single dates.
  49. MonthPickerMultiSelection(this.selectedDates);
  50. @override
  51. bool isAfter(DateTime dateTime) =>
  52. selectedDates.every((d) => d.isAfter(dateTime));
  53. @override
  54. bool isBefore(DateTime dateTime) =>
  55. selectedDates.every((d) => d.isBefore(dateTime));
  56. @override
  57. DateTime get earliest => DatePickerUtils.getEarliestFromList(selectedDates);
  58. @override
  59. DateTime get latest => DatePickerUtils.getLatestFromList(selectedDates);
  60. @override
  61. bool get isEmpty => selectedDates.isEmpty;
  62. @override
  63. bool get isNotEmpty => selectedDates.isNotEmpty;
  64. }