Skip to content

Commit

Permalink
fix: Fixes issue #426: πŸ› Fixed header style icons visibility on min &…
Browse files Browse the repository at this point in the history
… max dates.
  • Loading branch information
shubham-jitiya-simform committed Jan 3, 2025
1 parent 16ff6dc commit 157066d
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 35 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
78 changes: 47 additions & 31 deletions lib/src/components/headers/calendar_page_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
),
),
),
),
],
),
);
Expand Down
16 changes: 15 additions & 1 deletion lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
ScrollController get scrollController => _scrollController;

late VoidCallback _reloadCallback;
late HeaderStyle headerStyle;

final _scrollConfiguration = EventScrollConfiguration<T>();

Expand All @@ -368,6 +369,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
);
_pageController = PageController(initialPage: _currentIndex);
_eventArranger = widget.eventArranger ?? SideEventArranger<T>();
headerStyle = widget.headerStyle;
_assignBuilders();
}

Expand Down Expand Up @@ -701,7 +703,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
jumpToDate(selectedDate);
}
},
headerStyle: widget.headerStyle,
headerStyle: headerStyle,
);
}

Expand Down Expand Up @@ -756,6 +758,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
_currentDate.day + (index - _currentIndex),
);
_currentIndex = index;
_updateHeaderIcons();
});
}
if (!widget.keepScrollOffset) {
Expand All @@ -764,6 +767,17 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
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
Expand Down
18 changes: 16 additions & 2 deletions lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {

late VoidCallback _reloadCallback;

late HeaderStyle headerStyle;

@override
void initState() {
super.initState();
Expand All @@ -258,7 +260,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {

// Initialize page controller to control page actions.
_pageController = PageController(initialPage: _currentIndex);

headerStyle = widget.headerStyle;
_assignBuilders();
}

Expand Down Expand Up @@ -514,11 +516,23 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
_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(
Expand All @@ -541,7 +555,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
date: date,
dateStringBuilder: widget.headerStringBuilder,
onNextMonth: nextPage,
headerStyle: widget.headerStyle,
headerStyle: headerStyle,
);
}

Expand Down
30 changes: 30 additions & 0 deletions lib/src/style/header_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 18 additions & 1 deletion lib/src/week_view/week_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {

late int _startHour;
late int _endHour;
late HeaderStyle headerStyle;

final _scrollConfiguration = EventScrollConfiguration();

Expand Down Expand Up @@ -421,6 +422,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
_fullDayHeaderTitle = widget.fullDayHeaderTitle;
_fullDayHeaderTextConfig =
widget.fullDayHeaderTextConfig ?? FullDayHeaderTextConfig();
headerStyle = widget.headerStyle;
}

@override
Expand Down Expand Up @@ -853,7 +855,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
}
},
headerStringBuilder: widget.headerStringBuilder,
headerStyle: widget.headerStyle,
headerStyle: headerStyle,
);
}

Expand Down Expand Up @@ -898,11 +900,26 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
);
_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
Expand Down

0 comments on commit 157066d

Please sign in to comment.