Skip to content

Commit c74e545

Browse files
Revert "✨Fixes issue #233: Add selectedDate control to MonthView for external date management"
This reverts commit d702bca
1 parent 0cc89e4 commit c74e545

7 files changed

Lines changed: 15 additions & 233 deletions

File tree

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
- Added `DividerSettings` to customize the dividers in `WeekView` and `MultiDayView`. [#374](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/374), [#430](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/430), [#498](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/498)
55
- Added `timeSlotColorBuilder` in `DayView` and `WeekView` to customize background color. [#470](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/470)
66
- Added `pageDate` parameter for timeline label customization with current timestamp fallback. [#527](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/527)
7-
- Added `selectedDate` control to `MonthView` for external date management. [#233](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/233)
8-
- [BREAKING] Added `isSelected` parameter to `CellBuilder` typedef in `MonthView`. Custom cell builders must be updated to accept this new parameter.
97
- Added `showMidnightHour` parameter in `DayView` and `WeekView` to control whether the `00:00` label is shown on the timeline. Default is `false`. [#492](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/492)
108
- Added `onDateLongPressMoveUpdate` callback to `MonthView`, along with `MonthView.multiDateSelectionRange`, `MonthView.multiDateSelectionColor`, and `FilledCell.multipleDateSelectionColor` for multi-date selection customization. [#401](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/401)
119
- Updated documentation for `DayView`, `WeekView`, `MonthView` and `MultiDayView` to add more details about the parameters and their usage. [#448](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/pull/448)

doc/documentation.md

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ This guide covers more advanced features and customization options for the calen
172172
MonthView(
173173
controller: EventController(),
174174
width: 400, // Width of month view (if null, uses MediaQuery width)
175-
selectedDate: DateTime(2021, 8, 10), // Controls selected date in month grid
176175
// Set of dates that are selected via long press and drag
177176
multiDateSelectionRange: {DateTime(2021, 8, 12), DateTime(2021, 8, 13)},
178177
multiDateSelectionColor: Colors.blue.withOpacity(0.3), // Color of selected date cells
@@ -185,7 +184,6 @@ MonthView(
185184
onPageChange: (date, pageIndex) => print("$date, $pageIndex"),
186185
onCellTap: (events, date) {
187186
// Implement callback when user taps on a cell.
188-
// Update selectedDate here if you want controlled selection.
189187
print(events);
190188
},
191189
// Event callbacks
@@ -1028,7 +1026,7 @@ MonthView(
10281026
```dart
10291027
MonthView(
10301028
monthViewBuilders: MonthViewBuilders(
1031-
cellBuilder: (date, events, isToday, isInMonth, isSelected, hideDaysNotInMonth) {
1029+
cellBuilder: (date, events, isToday, isInMonth, hideDaysNotInMonth) {
10321030
return Container(
10331031
decoration: BoxDecoration(
10341032
color: isInMonth ? Colors.white : Colors.grey[200],
@@ -1038,8 +1036,8 @@ MonthView(
10381036
child: Text(
10391037
date.day.toString(),
10401038
style: TextStyle(
1041-
color: isSelected ? Colors.white : (isToday ? Colors.red : Colors.black),
1042-
fontWeight: (isToday || isSelected) ? FontWeight.bold : FontWeight.normal,
1039+
color: isToday ? Colors.red : Colors.black,
1040+
fontWeight: isToday ? FontWeight.bold : FontWeight.normal,
10431041
),
10441042
),
10451043
),
@@ -1136,29 +1134,6 @@ dependencies:
11361134
),
11371135
});
11381136
```
1139-
### 3. Migrate `CellBuilder`
1140-
1141-
```dart
1142-
// **Previous Signature (2.0.0):**
1143-
typedef CellBuilder<T extends Object?> = Widget Function(
1144-
DateTime date,
1145-
List<CalendarEventData<T>> event,
1146-
bool isToday,
1147-
bool isInMonth,
1148-
bool hideDaysNotInMonth,
1149-
);
1150-
```
1151-
```dart
1152-
// **New Signature (Latest):**
1153-
typedef CellBuilder<T extends Object?> = Widget Function(
1154-
DateTime date,
1155-
List<CalendarEventData<T>> event,
1156-
bool isToday,
1157-
bool isInMonth,
1158-
bool isSelected, // New parameter added
1159-
bool hideDaysNotInMonth,
1160-
);
1161-
```
11621137

11631138
# Contributors
11641139

example/lib/widgets/month_view_widget.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,9 @@ class MonthViewWidget extends StatefulWidget {
1616
}
1717

1818
class _MonthViewWidgetState extends State<MonthViewWidget> {
19-
late DateTime _selectedDate;
2019
DateTime? _multiSelectionStartDate;
2120
Set<DateTime> _multiSelectedDateRange = <DateTime>{};
2221

23-
@override
24-
void initState() {
25-
super.initState();
26-
_selectedDate = DateTime.now().withoutTime;
27-
}
28-
2922
@override
3023
Widget build(BuildContext context) {
3124
final translate = context.translate;
@@ -34,14 +27,10 @@ class _MonthViewWidgetState extends State<MonthViewWidget> {
3427
MonthView(
3528
key: widget.state,
3629
width: widget.width,
37-
selectedDate: _selectedDate,
3830
multiDateSelectionRange: _multiSelectedDateRange,
3931
multiDateSelectionColor: Colors.blue.withValues(alpha: 0.1),
4032
monthViewThemeSettings: MonthViewThemeSettings(
4133
cellsInMonthHighlightColor: Colors.blue,
42-
selectedHighlightColor: Colors.deepOrange,
43-
selectedTitleColor: Colors.white,
44-
selectedHighlightRadius: 12,
4534
),
4635
monthViewStyle: MonthViewStyle(
4736
startDay: WeekDays.friday,
@@ -78,7 +67,6 @@ class _MonthViewWidgetState extends State<MonthViewWidget> {
7867
_setSelectedRange(startDate, _normalizeDate(date));
7968
},
8069
onCellTap: (events, date) {
81-
setState(() => _selectedDate = date.withoutTime);
8270
final normalizedDate = _normalizeDate(date);
8371
if (_multiSelectedDateRange.isNotEmpty) {
8472
if (_multiSelectedDateRange.contains(normalizedDate)) {

lib/src/month_view/month_view.dart

Lines changed: 12 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class MonthView<T extends Object?> extends StatefulWidget {
1616
this.monthViewThemeSettings = const MonthViewThemeSettings(),
1717
this.controller,
1818
this.width,
19-
this.selectedDate,
2019
this.multiDateSelectionRange = const {},
2120
this.multiDateSelectionColor,
2221
}) : super(key: key);
@@ -45,13 +44,6 @@ class MonthView<T extends Object?> extends StatefulWidget {
4544
/// If null is provided then It will take width of closest [MediaQuery].
4645
final double? width;
4746

48-
/// Controls the selected date in the month grid.
49-
///
50-
/// When null, the view manages selection internally and updates it when a
51-
/// visible cell is tapped. When non-null, selection is controlled by the
52-
/// caller and taps only trigger [MonthViewBuilders.onCellTap].
53-
final DateTime? selectedDate;
54-
5547
/// Set of dates that are selected via [MonthViewBuilders.onDateLongPressMoveUpdate]
5648
final Set<DateTime> multiDateSelectionRange;
5749

@@ -101,9 +93,6 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
10193
/// Height of each cell in the month grid. Calculated based on cellAspectRatio.
10294
late double _cellHeight;
10395

104-
/// Current selected date (single date).
105-
DateTime? _selectedDate;
106-
10796
/// Builder function for rendering individual calendar cells.
10897
late CellBuilder<T> _cellBuilder;
10998

@@ -141,8 +130,6 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
141130

142131
_regulateCurrentDate();
143132

144-
_selectedDate = widget.selectedDate?.withoutTime;
145-
146133
// Initialize page controller to control page actions.
147134
_pageController = PageController(initialPage: _currentIndex);
148135

@@ -200,12 +187,6 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
200187
// Update builders and callbacks
201188
_assignBuilders();
202189

203-
if (widget.selectedDate != null) {
204-
_selectedDate = widget.selectedDate?.withoutTime;
205-
} else if (oldWidget.selectedDate != null) {
206-
_selectedDate = oldWidget.selectedDate?.withoutTime;
207-
}
208-
209190
updateViewDimensions();
210191
}
211192

@@ -335,7 +316,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
335316
width: _width,
336317
child: _MonthPageBuilder<T>(
337318
key: ValueKey(date.toIso8601String()),
338-
onCellTap: _handleCellTap,
319+
onCellTap: _monthViewBuilders.onCellTap,
339320
onDateLongPress:
340321
_monthViewBuilders.onDateLongPress,
341322
onDateLongPressMoveUpdate: _monthViewBuilders
@@ -348,7 +329,6 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
348329
borderColor: _monthViewStyle.borderColor,
349330
borderSize: _monthViewStyle.borderSize,
350331
cellBuilder: _cellBuilder,
351-
selectedDate: _selectedDate,
352332
cellRatio: _cellAspectRatio,
353333
date: date,
354334
showBorder: _monthViewStyle.showBorder,
@@ -405,14 +385,6 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
405385
return _controller!;
406386
}
407387

408-
bool _isSameDate(DateTime? first, DateTime? second) {
409-
if (first == null || second == null) {
410-
return first == second;
411-
}
412-
413-
return first.withoutTime.compareWithoutTime(second.withoutTime);
414-
}
415-
416388
void _reload() {
417389
if (mounted) {
418390
setState(() {});
@@ -579,7 +551,6 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
579551
List<CalendarEventData<T>> events,
580552
bool isToday,
581553
bool isInMonth,
582-
bool isSelected,
583554
bool hideDaysNotInMonth,
584555
) {
585556
// Normalize both the input date and selected dates to date-only (midnight)
@@ -590,27 +561,11 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
590561
);
591562
final color = isMultiSelected ? widget.multiDateSelectionColor : null;
592563
final themeColor = context.monthViewColors;
593-
final shouldHighlight = isSelected || isToday;
594-
final highlightedTitleColor = isSelected
595-
? _monthViewThemeSettings.selectedTitleColor
596-
: hideDaysNotInMonth
597-
? _monthViewThemeSettings.cellsNotInMonthHighlightedTitleColor
598-
: _monthViewThemeSettings.cellsInMonthHighlightedTitleColor;
599-
final highlightColor = isSelected
600-
? _monthViewThemeSettings.selectedHighlightColor
601-
: hideDaysNotInMonth
602-
? themeColor.cellHighlightColor
603-
: _monthViewThemeSettings.cellsInMonthHighlightColor;
604-
final highlightRadius = isSelected
605-
? _monthViewThemeSettings.selectedHighlightRadius
606-
: hideDaysNotInMonth
607-
? _monthViewThemeSettings.cellsNotInMonthHighlightRadius
608-
: _monthViewThemeSettings.cellsInMonthHighlightRadius;
609564

610565
if (hideDaysNotInMonth) {
611566
return FilledCell<T>(
612567
date: date,
613-
shouldHighlight: shouldHighlight,
568+
shouldHighlight: isToday,
614569
backgroundColor: isInMonth
615570
? themeColor.cellInMonthColor
616571
: themeColor.cellNotInMonthColor,
@@ -625,16 +580,17 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
625580
dateStringBuilder: _monthViewBuilders.dateStringBuilder,
626581
hideDaysNotInMonth: hideDaysNotInMonth,
627582
titleColor: themeColor.cellTextColor,
628-
highlightColor: highlightColor,
583+
highlightColor: themeColor.cellHighlightColor,
629584
tileColor: themeColor.weekDayTileColor,
630-
highlightRadius: highlightRadius,
631-
highlightedTitleColor: highlightedTitleColor,
585+
highlightRadius: _monthViewThemeSettings.cellsNotInMonthHighlightRadius,
586+
highlightedTitleColor:
587+
_monthViewThemeSettings.cellsNotInMonthHighlightedTitleColor,
632588
multipleDateSelectionColor: color,
633589
);
634590
}
635591
return FilledCell<T>(
636592
date: date,
637-
shouldHighlight: shouldHighlight,
593+
shouldHighlight: isToday,
638594
backgroundColor: isInMonth
639595
? themeColor.cellInMonthColor
640596
: themeColor.cellNotInMonthColor,
@@ -650,28 +606,15 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
650606
titleColor: isInMonth
651607
? themeColor.cellTextColor
652608
: themeColor.cellTextColor.withAlpha(150),
653-
highlightedTitleColor: highlightedTitleColor,
654-
highlightRadius: highlightRadius,
609+
highlightedTitleColor:
610+
_monthViewThemeSettings.cellsInMonthHighlightedTitleColor,
611+
highlightRadius: _monthViewThemeSettings.cellsInMonthHighlightRadius,
655612
tileColor: _monthViewThemeSettings.cellsInMonthTileColor,
656-
highlightColor: highlightColor,
613+
highlightColor: _monthViewThemeSettings.cellsInMonthHighlightColor,
657614
multipleDateSelectionColor: color,
658615
);
659616
}
660617

661-
/// Handles cell tap event. Updates selected date if [widget.selectedDate]
662-
/// is null and calls [MonthViewBuilders.onCellTap] callback.
663-
void _handleCellTap(List<CalendarEventData<T>> events, DateTime date) {
664-
if (widget.selectedDate == null &&
665-
!_isSameDate(_selectedDate, date.withoutTime) &&
666-
mounted) {
667-
setState(() {
668-
_selectedDate = date.withoutTime;
669-
});
670-
}
671-
672-
_monthViewBuilders.onCellTap?.call(events, date);
673-
}
674-
675618
/// Animate to next page (next month).
676619
///
677620
/// Arguments [duration] and [curve] will override default values provided
@@ -785,7 +728,6 @@ class _MonthPageBuilder<T> extends StatefulWidget {
785728
required this.showBorder,
786729
required this.borderSize,
787730
required this.cellBuilder,
788-
required this.selectedDate,
789731
required this.date,
790732
required this.controller,
791733
required this.width,
@@ -819,7 +761,6 @@ class _MonthPageBuilder<T> extends StatefulWidget {
819761
final ScrollPhysics physics;
820762
final bool hideDaysNotInMonth;
821763
final int weekDays;
822-
final DateTime? selectedDate;
823764

824765
@override
825766
State<_MonthPageBuilder<T>> createState() => _MonthPageBuilderState<T>();
@@ -863,9 +804,7 @@ class _MonthPageBuilderState<T> extends State<_MonthPageBuilder<T>> {
863804
(monthDays[index].month != widget.date.month)
864805
? <CalendarEventData<T>>[]
865806
: widget.controller.getEventsOnDay(monthDays[index]);
866-
final isSelected =
867-
widget.selectedDate?.compareWithoutTime(monthDays[index]) ??
868-
false;
807+
869808
return GestureDetector(
870809
behavior: HitTestBehavior.opaque,
871810
onTap: () => widget.onCellTap?.call(events, monthDays[index]),
@@ -884,7 +823,6 @@ class _MonthPageBuilderState<T> extends State<_MonthPageBuilder<T>> {
884823
events,
885824
monthDays[index].compareWithoutTime(DateTime.now()),
886825
monthDays[index].month == widget.date.month,
887-
isSelected,
888826
widget.hideDaysNotInMonth,
889827
),
890828
),

lib/src/month_view/month_view_theme_settings.dart

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ class MonthViewThemeSettings {
1919
this.cellsInMonthHighlightRadius = 11,
2020
this.cellsInMonthTileColor = Colors.blue,
2121
this.cellsInMonthHighlightColor = Colors.blue,
22-
this.selectedHighlightColor = Colors.blue,
23-
this.selectedTitleColor = Constants.white,
24-
this.selectedHighlightRadius = 11,
2522
});
2623

2724
/// Default border color for week day cells.
@@ -57,15 +54,6 @@ class MonthViewThemeSettings {
5754
/// Highlight color for cells in the current month.
5855
final Color cellsInMonthHighlightColor;
5956

60-
/// Highlight color for the selected date.
61-
final Color selectedHighlightColor;
62-
63-
/// Title color for the selected date.
64-
final Color selectedTitleColor;
65-
66-
/// Highlight radius for the selected date.
67-
final double selectedHighlightRadius;
68-
6957
/// Creates a copy of this theme settings with the given fields replaced.
7058
MonthViewThemeSettings copyWith({
7159
Color? weekDayBorderColor,
@@ -79,9 +67,6 @@ class MonthViewThemeSettings {
7967
double? cellsInMonthHighlightRadius,
8068
Color? cellsInMonthTileColor,
8169
Color? cellsInMonthHighlightColor,
82-
Color? selectedHighlightColor,
83-
Color? selectedTitleColor,
84-
double? selectedHighlightRadius,
8570
}) {
8671
return MonthViewThemeSettings(
8772
weekDayBorderColor: weekDayBorderColor ?? this.weekDayBorderColor,
@@ -103,11 +88,6 @@ class MonthViewThemeSettings {
10388
cellsInMonthTileColor ?? this.cellsInMonthTileColor,
10489
cellsInMonthHighlightColor:
10590
cellsInMonthHighlightColor ?? this.cellsInMonthHighlightColor,
106-
selectedHighlightColor:
107-
selectedHighlightColor ?? this.selectedHighlightColor,
108-
selectedTitleColor: selectedTitleColor ?? this.selectedTitleColor,
109-
selectedHighlightRadius:
110-
selectedHighlightRadius ?? this.selectedHighlightRadius,
11191
);
11292
}
11393

@@ -128,9 +108,6 @@ class MonthViewThemeSettings {
128108
cellsInMonthHighlightRadius: other.cellsInMonthHighlightRadius,
129109
cellsInMonthTileColor: other.cellsInMonthTileColor,
130110
cellsInMonthHighlightColor: other.cellsInMonthHighlightColor,
131-
selectedHighlightColor: other.selectedHighlightColor,
132-
selectedTitleColor: other.selectedTitleColor,
133-
selectedHighlightRadius: other.selectedHighlightRadius,
134111
);
135112
}
136113
}

lib/src/typedefs.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ typedef CellBuilder<T extends Object?> = Widget Function(
1111
List<CalendarEventData<T>> event,
1212
bool isToday,
1313
bool isInMonth,
14-
bool isSelected,
1514
bool hideDaysNotInMonth,
1615
);
1716

0 commit comments

Comments
 (0)