From cf7f28c8a302777f2128677a3cdc00c95323e3e3 Mon Sep 17 00:00:00 2001 From: Shubham Jitiya Date: Wed, 11 Dec 2024 20:23:11 +0530 Subject: [PATCH] =?UTF-8?q?fix:=20Fixes=20issue=20#426:=20=F0=9F=90=9B=20F?= =?UTF-8?q?ixed=20header=20style=20icons=20visibility=20on=20min=20&=20max?= =?UTF-8?q?=20dates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 + .../headers/calendar_page_header.dart | 83 +++++++++++-------- .../components/headers/day_page_header.dart | 5 ++ .../components/headers/month_page_header.dart | 4 + .../components/headers/week_page_header.dart | 4 + lib/src/day_view/day_view.dart | 17 ++++ lib/src/month_view/month_view.dart | 6 +- lib/src/week_view/week_view.dart | 6 ++ 8 files changed, 93 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88551ec0..fb8c873e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ - Fixes `startHour` and `endHour` not updating when rebuilding in week view. [#410](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/410) - Fixes issue of header icon `color` property in `IconDataConfig`. - Adds support for single day & full day recurring events. [#378](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/378) +- Fixes `HeaderStyle` icons visibility on min & max dates reached. [#429](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/429) +- Fixes inconsistent padding issue of right icon in the `HeaderStyle`. # [1.3.0 - 12 Nov 2024](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.3.0) diff --git a/lib/src/components/headers/calendar_page_header.dart b/lib/src/components/headers/calendar_page_header.dart index eda855c9..a2c6270e 100644 --- a/lib/src/components/headers/calendar_page_header.dart +++ b/lib/src/components/headers/calendar_page_header.dart @@ -17,11 +17,17 @@ class CalendarPageHeader extends StatelessWidget { /// This will be ignored if right icon is provided in [headerStyle]. final VoidCallback? onNextDay; + // TODO(Shubham): Add comment + final bool showNextIcon; + /// When user taps on left arrow. /// /// This will be ignored if left icon is provided in [headerStyle]. final VoidCallback? onPreviousDay; + // TODO(Shubham): Add comment + final bool showPreviousIcon; + /// When user taps on title. /// /// This will be ignored if [titleBuilder] is provided. @@ -78,8 +84,10 @@ class CalendarPageHeader extends StatelessWidget { this.dateStringBuilder, this.titleBuilder, this.onNextDay, + this.showNextIcon = true, this.onTitleTapped, this.onPreviousDay, + this.showPreviousIcon = true, this.secondaryDate, @Deprecated("Use HeaderStyle.decoration to provide background") this.backgroundColor = Constants.headerBackground, @@ -103,23 +111,27 @@ class CalendarPageHeader extends StatelessWidget { mainAxisSize: headerStyle.mainAxisSize, mainAxisAlignment: headerStyle.mainAxisAlignment, children: [ - if (headerStyle.leftIconVisible && headerStyle.leftIconConfig != null) - headerStyle.leftIconConfig!.icon?.call(context) ?? - IconButton( - onPressed: onPreviousDay, - splashColor: Colors.transparent, - focusColor: Colors.transparent, - hoverColor: Colors.transparent, - highlightColor: Colors.transparent, - padding: headerStyle.leftIconPadding ?? - headerStyle.leftIconConfig!.padding, - icon: headerStyle.leftIcon ?? - Icon( - Icons.chevron_left, - size: headerStyle.leftIconConfig!.size, - color: iconColor ?? headerStyle.leftIconConfig!.color, - ), - ), + if ((headerStyle.leftIconVisible) && + headerStyle.leftIconConfig != null) + Opacity( + opacity: showPreviousIcon ? 1 : 0, + child: headerStyle.leftIconConfig!.icon?.call(context) ?? + IconButton( + onPressed: onPreviousDay, + splashColor: Colors.transparent, + focusColor: Colors.transparent, + hoverColor: Colors.transparent, + highlightColor: Colors.transparent, + padding: headerStyle.leftIconPadding ?? + headerStyle.leftIconConfig!.padding, + icon: headerStyle.leftIcon ?? + Icon( + Icons.chevron_left, + size: headerStyle.leftIconConfig!.size, + color: iconColor ?? headerStyle.leftIconConfig!.color, + ), + ), + ), Expanded( child: titleBuilder != null ? DefaultTextStyle.merge( @@ -140,23 +152,28 @@ class CalendarPageHeader extends StatelessWidget { ), ), ), - if (headerStyle.rightIconVisible && + if ((headerStyle.rightIconVisible) && headerStyle.rightIconConfig != null) - headerStyle.rightIconConfig!.icon?.call(context) ?? - IconButton( - onPressed: onNextDay, - splashColor: Colors.transparent, - focusColor: Colors.transparent, - hoverColor: Colors.transparent, - highlightColor: Colors.transparent, - padding: headerStyle.rightIconPadding, - icon: headerStyle.rightIcon ?? - Icon( - Icons.chevron_right, - size: headerStyle.rightIconConfig?.size, - color: iconColor ?? headerStyle.rightIconConfig?.color, - ), - ), + Opacity( + opacity: showNextIcon ? 1 : 0, + child: headerStyle.rightIconConfig!.icon?.call(context) ?? + IconButton( + onPressed: onNextDay, + splashColor: Colors.transparent, + focusColor: Colors.transparent, + hoverColor: Colors.transparent, + highlightColor: Colors.transparent, + padding: headerStyle.rightIconPadding ?? + headerStyle.rightIconConfig!.padding, + icon: headerStyle.rightIcon ?? + Icon( + Icons.chevron_right, + size: headerStyle.rightIconConfig?.size, + color: + iconColor ?? headerStyle.rightIconConfig?.color, + ), + ), + ), ], ), ); diff --git a/lib/src/components/headers/day_page_header.dart b/lib/src/components/headers/day_page_header.dart index b4ca4c6c..22e43a5e 100644 --- a/lib/src/components/headers/day_page_header.dart +++ b/lib/src/components/headers/day_page_header.dart @@ -16,8 +16,10 @@ class DayPageHeader extends CalendarPageHeader { const DayPageHeader({ Key? key, VoidCallback? onNextDay, + bool showNextIcon = true, AsyncCallback? onTitleTapped, VoidCallback? onPreviousDay, + bool showPreviousIcon = true, StringProvider? dateStringBuilder, required DateTime date, @Deprecated("Use HeaderStyle to provide icon color") Color? iconColor, @@ -31,7 +33,10 @@ class DayPageHeader extends CalendarPageHeader { backgroundColor: backgroundColor, iconColor: iconColor, onNextDay: onNextDay, + + showNextIcon: showNextIcon, onPreviousDay: onPreviousDay, + showPreviousIcon: showPreviousIcon, onTitleTapped: onTitleTapped, dateStringBuilder: dateStringBuilder ?? DayPageHeader._dayStringBuilder, diff --git a/lib/src/components/headers/month_page_header.dart b/lib/src/components/headers/month_page_header.dart index 133f0189..2df8f6c4 100644 --- a/lib/src/components/headers/month_page_header.dart +++ b/lib/src/components/headers/month_page_header.dart @@ -15,8 +15,10 @@ class MonthPageHeader extends CalendarPageHeader { const MonthPageHeader({ Key? key, VoidCallback? onNextMonth, + bool showNextIcon = true, AsyncCallback? onTitleTapped, VoidCallback? onPreviousMonth, + bool showPreviousIcon = true, @Deprecated("Use HeaderStyle to provide icon color") Color? iconColor, @Deprecated("Use HeaderStyle to provide background color") Color backgroundColor = Constants.headerBackground, @@ -27,7 +29,9 @@ class MonthPageHeader extends CalendarPageHeader { key: key, date: date, onNextDay: onNextMonth, + showNextIcon: showNextIcon, onPreviousDay: onPreviousMonth, + showPreviousIcon: showPreviousIcon, onTitleTapped: onTitleTapped, // ignore_for_file: deprecated_member_use_from_same_package backgroundColor: backgroundColor, diff --git a/lib/src/components/headers/week_page_header.dart b/lib/src/components/headers/week_page_header.dart index e64e88ae..4d22c03e 100644 --- a/lib/src/components/headers/week_page_header.dart +++ b/lib/src/components/headers/week_page_header.dart @@ -15,8 +15,10 @@ class WeekPageHeader extends CalendarPageHeader { const WeekPageHeader({ Key? key, VoidCallback? onNextDay, + bool showNextIcon = true, AsyncCallback? onTitleTapped, VoidCallback? onPreviousDay, + bool showPreviousIcon = true, required DateTime startDate, required DateTime endDate, @Deprecated("Use HeaderStyle to provide icon color") Color? iconColor, @@ -29,7 +31,9 @@ class WeekPageHeader extends CalendarPageHeader { date: startDate, secondaryDate: endDate, onNextDay: onNextDay, + showNextIcon: showNextIcon, onPreviousDay: onPreviousDay, + showPreviousIcon: showPreviousIcon, onTitleTapped: onTitleTapped, // ignore_for_file: deprecated_member_use_from_same_package iconColor: iconColor, diff --git a/lib/src/day_view/day_view.dart b/lib/src/day_view/day_view.dart index 35e76bf4..653a1a62 100644 --- a/lib/src/day_view/day_view.dart +++ b/lib/src/day_view/day_view.dart @@ -681,10 +681,15 @@ class DayViewState extends State> { /// [widget.dayTitleBuilder] is null. /// Widget _defaultDayBuilder(DateTime date) { + final showLeftIcon = date != CalendarConstants.epochDate; + final showRightIcon = date != CalendarConstants.maxDate; + return DayPageHeader( date: _currentDate, dateStringBuilder: widget.dateStringBuilder, onNextDay: nextPage, + showPreviousIcon: showLeftIcon, + showNextIcon: showRightIcon, onPreviousDay: previousPage, onTitleTapped: () async { if (widget.onHeaderTitleTap != null) { @@ -764,6 +769,18 @@ class DayViewState extends State> { widget.onPageChange?.call(_currentDate, _currentIndex); } + // Hide header icons if end dates are reached + // TODO(Shubham): Not required remove this + // void _updateHeaderIcons() { + // bool setLeftIconToNull = _currentDate == _minDate; + // bool setRightIconToNull = _currentDate == _maxDate; + // + // headerStyle = widget.headerStyle.copyWith( + // setLeftIconConfigToNull: setLeftIconToNull, + // setRightIconConfigToNull: setRightIconToNull, + // ); + // } + /// Animate to next page /// /// Arguments [duration] and [curve] will override default values provided diff --git a/lib/src/month_view/month_view.dart b/lib/src/month_view/month_view.dart index 1b67b8f5..dafa9630 100644 --- a/lib/src/month_view/month_view.dart +++ b/lib/src/month_view/month_view.dart @@ -258,7 +258,6 @@ class MonthViewState extends State> { // Initialize page controller to control page actions. _pageController = PageController(initialPage: _currentIndex); - _assignBuilders(); } @@ -521,7 +520,12 @@ class MonthViewState extends State> { /// Default month view header builder Widget _defaultHeaderBuilder(DateTime date) { + final showLeftIcon = date != CalendarConstants.epochDate; + final showRightIcon = date != CalendarConstants.maxDate; + return MonthPageHeader( + showPreviousIcon: showLeftIcon, + showNextIcon: showRightIcon, onTitleTapped: () async { if (widget.onHeaderTitleTap != null) { widget.onHeaderTitleTap!(date); diff --git a/lib/src/week_view/week_view.dart b/lib/src/week_view/week_view.dart index 19c651b4..03dfcbba 100644 --- a/lib/src/week_view/week_view.dart +++ b/lib/src/week_view/week_view.dart @@ -832,11 +832,17 @@ class WeekViewState extends State> { DateTime startDate, DateTime endDate, ) { + final showLeftIcon = + !startDate.isAtSameMomentAs(CalendarConstants.epochDate); + final showRightIcon = endDate != CalendarConstants.maxDate; + return WeekPageHeader( startDate: _currentStartDate, endDate: _currentEndDate, onNextDay: nextPage, + showNextIcon: showRightIcon, onPreviousDay: previousPage, + showPreviousIcon: showLeftIcon, onTitleTapped: () async { if (widget.onHeaderTitleTap != null) { widget.onHeaderTitleTap!(startDate);