From 157066d9e190bad318bb21130718b7a64fd7c9af 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 | 78 +++++++++++-------- lib/src/day_view/day_view.dart | 16 +++- lib/src/month_view/month_view.dart | 18 ++++- lib/src/style/header_style.dart | 30 +++++++ lib/src/week_view/week_view.dart | 19 ++++- 6 files changed, 128 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8874bd03..b3d70688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - Fixes tap `onTileDoubleTap` & `onTileLongTap` issue for `hideDaysNotInMonth` in month view. [#435](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/435) - 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`. +- 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..eb683ea7 100644 --- a/lib/src/components/headers/calendar_page_header.dart +++ b/lib/src/components/headers/calendar_page_header.dart @@ -104,23 +104,31 @@ class CalendarPageHeader extends StatelessWidget { 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, - ), - ), + Expanded( + child: Align( + alignment: Alignment.centerLeft, + 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, + ), + ), + ), + ), + if (headerStyle.leftIconConfig == null) const Spacer(), Expanded( + flex: 4, child: titleBuilder != null ? DefaultTextStyle.merge( style: headerStyle.headerTextStyle, @@ -140,23 +148,31 @@ class CalendarPageHeader extends StatelessWidget { ), ), ), + if (headerStyle.rightIconConfig == null) const Spacer(), 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, - ), - ), + Expanded( + child: Align( + alignment: Alignment.centerRight, + 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/day_view/day_view.dart b/lib/src/day_view/day_view.dart index 35e76bf4..9254f610 100644 --- a/lib/src/day_view/day_view.dart +++ b/lib/src/day_view/day_view.dart @@ -346,6 +346,7 @@ class DayViewState extends State> { ScrollController get scrollController => _scrollController; late VoidCallback _reloadCallback; + late HeaderStyle headerStyle; final _scrollConfiguration = EventScrollConfiguration(); @@ -368,6 +369,7 @@ class DayViewState extends State> { ); _pageController = PageController(initialPage: _currentIndex); _eventArranger = widget.eventArranger ?? SideEventArranger(); + headerStyle = widget.headerStyle; _assignBuilders(); } @@ -701,7 +703,7 @@ class DayViewState extends State> { jumpToDate(selectedDate); } }, - headerStyle: widget.headerStyle, + headerStyle: headerStyle, ); } @@ -756,6 +758,7 @@ class DayViewState extends State> { _currentDate.day + (index - _currentIndex), ); _currentIndex = index; + _updateHeaderIcons(); }); } if (!widget.keepScrollOffset) { @@ -764,6 +767,17 @@ class DayViewState extends State> { widget.onPageChange?.call(_currentDate, _currentIndex); } + // Hide header icons if end dates are reached + 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 963b3d66..3dd02dc0 100644 --- a/lib/src/month_view/month_view.dart +++ b/lib/src/month_view/month_view.dart @@ -243,6 +243,8 @@ class MonthViewState extends State> { late VoidCallback _reloadCallback; + late HeaderStyle headerStyle; + @override void initState() { super.initState(); @@ -258,7 +260,7 @@ class MonthViewState extends State> { // Initialize page controller to control page actions. _pageController = PageController(initialPage: _currentIndex); - + headerStyle = widget.headerStyle; _assignBuilders(); } @@ -514,11 +516,23 @@ class MonthViewState extends State> { _currentDate.month + (value - _currentIndex), ); _currentIndex = value; + _updateHeaderIcons(); }); } widget.onPageChange?.call(_currentDate, _currentIndex); } + // Hide header icons if end dates are reached + void _updateHeaderIcons() { + bool setLeftIconToNull = _currentDate == _minDate; + bool setRightIconToNull = _currentDate == _maxDate; + + headerStyle = widget.headerStyle.copyWith( + setLeftIconConfigToNull: setLeftIconToNull, + setRightIconConfigToNull: setRightIconToNull, + ); + } + /// Default month view header builder Widget _defaultHeaderBuilder(DateTime date) { return MonthPageHeader( @@ -541,7 +555,7 @@ class MonthViewState extends State> { date: date, dateStringBuilder: widget.headerStringBuilder, onNextMonth: nextPage, - headerStyle: widget.headerStyle, + headerStyle: headerStyle, ); } diff --git a/lib/src/style/header_style.dart b/lib/src/style/header_style.dart index b7728ff3..ffa5d957 100644 --- a/lib/src/style/header_style.dart +++ b/lib/src/style/header_style.dart @@ -101,6 +101,36 @@ class HeaderStyle { this.rightIconPadding, }); + HeaderStyle copyWith({ + TextStyle? headerTextStyle, + EdgeInsets? headerMargin, + EdgeInsets? headerPadding, + TextAlign? titleAlign, + BoxDecoration? decoration, + MainAxisAlignment? mainAxisAlignment, + IconDataConfig? leftIconConfig, + bool setLeftIconConfigToNull = false, + IconDataConfig? rightIconConfig, + bool setRightIconConfigToNull = false, + MainAxisSize? mainAxisSize, + }) { + return HeaderStyle( + headerTextStyle: headerTextStyle ?? this.headerTextStyle, + headerMargin: headerMargin ?? this.headerMargin, + headerPadding: headerPadding ?? this.headerPadding, + titleAlign: titleAlign ?? this.titleAlign, + decoration: decoration ?? this.decoration, + mainAxisAlignment: mainAxisAlignment ?? this.mainAxisAlignment, + leftIconConfig: setLeftIconConfigToNull + ? null + : (leftIconConfig ?? this.leftIconConfig), + rightIconConfig: setRightIconConfigToNull + ? null + : (rightIconConfig ?? this.rightIconConfig), + mainAxisSize: mainAxisSize ?? this.mainAxisSize, + ); + } + /// Create a `HeaderStyle` of calendar view /// /// Used when you need to use same configs for left and right icons. diff --git a/lib/src/week_view/week_view.dart b/lib/src/week_view/week_view.dart index 19c651b4..2c8acbcb 100644 --- a/lib/src/week_view/week_view.dart +++ b/lib/src/week_view/week_view.dart @@ -389,6 +389,7 @@ class WeekViewState extends State> { late int _startHour; late int _endHour; + late HeaderStyle headerStyle; final _scrollConfiguration = EventScrollConfiguration(); @@ -421,6 +422,7 @@ class WeekViewState extends State> { _fullDayHeaderTitle = widget.fullDayHeaderTitle; _fullDayHeaderTextConfig = widget.fullDayHeaderTextConfig ?? FullDayHeaderTextConfig(); + headerStyle = widget.headerStyle; } @override @@ -853,7 +855,7 @@ class WeekViewState extends State> { } }, headerStringBuilder: widget.headerStringBuilder, - headerStyle: widget.headerStyle, + headerStyle: headerStyle, ); } @@ -898,11 +900,26 @@ class WeekViewState extends State> { ); _currentEndDate = _currentStartDate.add(Duration(days: 6)); _currentIndex = index; + _updateHeaderIcons(); }); } widget.onPageChange?.call(_currentStartDate, _currentIndex); } + // Hide header icons if end dates are reached + void _updateHeaderIcons() { + final setLeftIconToNull = _currentStartDate == _minDate; + final setRightIconToNull = _currentStartDate.add( + const Duration(days: 6), + ) == + _maxDate; + + headerStyle = widget.headerStyle.copyWith( + setLeftIconConfigToNull: setLeftIconToNull, + setRightIconConfigToNull: setRightIconToNull, + ); + } + /// Animate to next page /// /// Arguments [duration] and [curve] will override default values provided