Skip to content

Commit d822044

Browse files
authored
Merge pull request #429 from SimformSolutionsPvtLtd/fix/issue_426_disable_buttons_calendar_header
fix: Fixes issue #426: 🐛 Fix header style icons visibility on min & max dates
2 parents 501bdb5 + 0cc4730 commit d822044

File tree

8 files changed

+75
-31
lines changed

8 files changed

+75
-31
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- Fixes `startHour` and `endHour` not updating when rebuilding in week view. [#410](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/410)
1010
- Fixes issue of header icon `color` property in `IconDataConfig`.
1111
- Adds support for single day & full day recurring events. [#378](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/378)
12+
- Fixes `HeaderStyle` icons visibility on min & max dates reached. [#429](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/429)
13+
- Fixes inconsistent padding issue of right icon in the `HeaderStyle`.
1214

1315
# [1.3.0 - 12 Nov 2024](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.3.0)
1416

lib/src/components/headers/calendar_page_header.dart

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ class CalendarPageHeader extends StatelessWidget {
1717
/// This will be ignored if right icon is provided in [headerStyle].
1818
final VoidCallback? onNextDay;
1919

20+
/// Hide & show right icon
21+
final bool showNextIcon;
22+
2023
/// When user taps on left arrow.
2124
///
2225
/// This will be ignored if left icon is provided in [headerStyle].
2326
final VoidCallback? onPreviousDay;
2427

28+
/// Hide & show left icon
29+
final bool showPreviousIcon;
30+
2531
/// When user taps on title.
2632
///
2733
/// This will be ignored if [titleBuilder] is provided.
@@ -78,8 +84,10 @@ class CalendarPageHeader extends StatelessWidget {
7884
this.dateStringBuilder,
7985
this.titleBuilder,
8086
this.onNextDay,
87+
this.showNextIcon = true,
8188
this.onTitleTapped,
8289
this.onPreviousDay,
90+
this.showPreviousIcon = true,
8391
this.secondaryDate,
8492
@Deprecated("Use HeaderStyle.decoration to provide background")
8593
this.backgroundColor = Constants.headerBackground,
@@ -104,22 +112,29 @@ class CalendarPageHeader extends StatelessWidget {
104112
mainAxisAlignment: headerStyle.mainAxisAlignment,
105113
children: [
106114
if (headerStyle.leftIconVisible && headerStyle.leftIconConfig != null)
107-
headerStyle.leftIconConfig!.icon?.call(context) ??
108-
IconButton(
109-
onPressed: onPreviousDay,
110-
splashColor: Colors.transparent,
111-
focusColor: Colors.transparent,
112-
hoverColor: Colors.transparent,
113-
highlightColor: Colors.transparent,
114-
padding: headerStyle.leftIconPadding ??
115-
headerStyle.leftIconConfig!.padding,
116-
icon: headerStyle.leftIcon ??
117-
Icon(
118-
Icons.chevron_left,
119-
size: headerStyle.leftIconConfig!.size,
120-
color: iconColor ?? headerStyle.leftIconConfig!.color,
121-
),
122-
),
115+
AbsorbPointer(
116+
absorbing: !showPreviousIcon,
117+
child: Opacity(
118+
opacity: showPreviousIcon ? 1 : 0,
119+
child: headerStyle.leftIconConfig!.icon?.call(context) ??
120+
IconButton(
121+
onPressed: onPreviousDay,
122+
splashColor: Colors.transparent,
123+
focusColor: Colors.transparent,
124+
hoverColor: Colors.transparent,
125+
highlightColor: Colors.transparent,
126+
padding: headerStyle.leftIconPadding ??
127+
headerStyle.leftIconConfig!.padding,
128+
icon: headerStyle.leftIcon ??
129+
Icon(
130+
Icons.chevron_left,
131+
size: headerStyle.leftIconConfig!.size,
132+
color:
133+
iconColor ?? headerStyle.leftIconConfig!.color,
134+
),
135+
),
136+
),
137+
),
123138
Expanded(
124139
child: titleBuilder != null
125140
? DefaultTextStyle.merge(
@@ -142,21 +157,29 @@ class CalendarPageHeader extends StatelessWidget {
142157
),
143158
if (headerStyle.rightIconVisible &&
144159
headerStyle.rightIconConfig != null)
145-
headerStyle.rightIconConfig!.icon?.call(context) ??
146-
IconButton(
147-
onPressed: onNextDay,
148-
splashColor: Colors.transparent,
149-
focusColor: Colors.transparent,
150-
hoverColor: Colors.transparent,
151-
highlightColor: Colors.transparent,
152-
padding: headerStyle.rightIconPadding,
153-
icon: headerStyle.rightIcon ??
154-
Icon(
155-
Icons.chevron_right,
156-
size: headerStyle.rightIconConfig?.size,
157-
color: iconColor ?? headerStyle.rightIconConfig?.color,
158-
),
159-
),
160+
AbsorbPointer(
161+
absorbing: !showNextIcon,
162+
child: Opacity(
163+
opacity: showNextIcon ? 1 : 0,
164+
child: headerStyle.rightIconConfig!.icon?.call(context) ??
165+
IconButton(
166+
onPressed: onNextDay,
167+
splashColor: Colors.transparent,
168+
focusColor: Colors.transparent,
169+
hoverColor: Colors.transparent,
170+
highlightColor: Colors.transparent,
171+
padding: headerStyle.rightIconPadding ??
172+
headerStyle.rightIconConfig!.padding,
173+
icon: headerStyle.rightIcon ??
174+
Icon(
175+
Icons.chevron_right,
176+
size: headerStyle.rightIconConfig?.size,
177+
color:
178+
iconColor ?? headerStyle.rightIconConfig?.color,
179+
),
180+
),
181+
),
182+
),
160183
],
161184
),
162185
);

lib/src/components/headers/day_page_header.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ class DayPageHeader extends CalendarPageHeader {
1616
const DayPageHeader({
1717
Key? key,
1818
VoidCallback? onNextDay,
19+
bool showNextIcon = true,
1920
AsyncCallback? onTitleTapped,
2021
VoidCallback? onPreviousDay,
22+
bool showPreviousIcon = true,
2123
StringProvider? dateStringBuilder,
2224
required DateTime date,
2325
@Deprecated("Use HeaderStyle to provide icon color") Color? iconColor,
@@ -31,7 +33,10 @@ class DayPageHeader extends CalendarPageHeader {
3133
backgroundColor: backgroundColor,
3234
iconColor: iconColor,
3335
onNextDay: onNextDay,
36+
37+
showNextIcon: showNextIcon,
3438
onPreviousDay: onPreviousDay,
39+
showPreviousIcon: showPreviousIcon,
3540
onTitleTapped: onTitleTapped,
3641
dateStringBuilder:
3742
dateStringBuilder ?? DayPageHeader._dayStringBuilder,

lib/src/components/headers/month_page_header.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ class MonthPageHeader extends CalendarPageHeader {
1515
const MonthPageHeader({
1616
Key? key,
1717
VoidCallback? onNextMonth,
18+
bool showNextIcon = true,
1819
AsyncCallback? onTitleTapped,
1920
VoidCallback? onPreviousMonth,
21+
bool showPreviousIcon = true,
2022
@Deprecated("Use HeaderStyle to provide icon color") Color? iconColor,
2123
@Deprecated("Use HeaderStyle to provide background color")
2224
Color backgroundColor = Constants.headerBackground,
@@ -27,7 +29,9 @@ class MonthPageHeader extends CalendarPageHeader {
2729
key: key,
2830
date: date,
2931
onNextDay: onNextMonth,
32+
showNextIcon: showNextIcon,
3033
onPreviousDay: onPreviousMonth,
34+
showPreviousIcon: showPreviousIcon,
3135
onTitleTapped: onTitleTapped,
3236
// ignore_for_file: deprecated_member_use_from_same_package
3337
backgroundColor: backgroundColor,

lib/src/components/headers/week_page_header.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ class WeekPageHeader extends CalendarPageHeader {
1515
const WeekPageHeader({
1616
Key? key,
1717
VoidCallback? onNextDay,
18+
bool showNextIcon = true,
1819
AsyncCallback? onTitleTapped,
1920
VoidCallback? onPreviousDay,
21+
bool showPreviousIcon = true,
2022
required DateTime startDate,
2123
required DateTime endDate,
2224
@Deprecated("Use HeaderStyle to provide icon color") Color? iconColor,
@@ -29,7 +31,9 @@ class WeekPageHeader extends CalendarPageHeader {
2931
date: startDate,
3032
secondaryDate: endDate,
3133
onNextDay: onNextDay,
34+
showNextIcon: showNextIcon,
3235
onPreviousDay: onPreviousDay,
36+
showPreviousIcon: showPreviousIcon,
3337
onTitleTapped: onTitleTapped,
3438
// ignore_for_file: deprecated_member_use_from_same_package
3539
iconColor: iconColor,

lib/src/day_view/day_view.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,9 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
685685
date: _currentDate,
686686
dateStringBuilder: widget.dateStringBuilder,
687687
onNextDay: nextPage,
688+
showNextIcon: date != _maxDate,
688689
onPreviousDay: previousPage,
690+
showPreviousIcon: date != _minDate,
689691
onTitleTapped: () async {
690692
if (widget.onHeaderTitleTap != null) {
691693
widget.onHeaderTitleTap!(date);

lib/src/month_view/month_view.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
522522
/// Default month view header builder
523523
Widget _defaultHeaderBuilder(DateTime date) {
524524
return MonthPageHeader(
525+
showPreviousIcon: date != _minDate,
526+
showNextIcon: date != _maxDate,
525527
onTitleTapped: () async {
526528
if (widget.onHeaderTitleTap != null) {
527529
widget.onHeaderTitleTap!(date);

lib/src/week_view/week_view.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,9 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
836836
startDate: _currentStartDate,
837837
endDate: _currentEndDate,
838838
onNextDay: nextPage,
839+
showNextIcon: endDate != _maxDate,
839840
onPreviousDay: previousPage,
841+
showPreviousIcon: startDate != _minDate,
840842
onTitleTapped: () async {
841843
if (widget.onHeaderTitleTap != null) {
842844
widget.onHeaderTitleTap!(startDate);

0 commit comments

Comments
 (0)