Skip to content

Commit

Permalink
fix: Fixes issue #426: Fixed header style icons visibility on min & m…
Browse files Browse the repository at this point in the history
…ax dates.
  • Loading branch information
shubham-jitiya-simform committed Dec 11, 2024
1 parent b536018 commit d108fd2
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 32 deletions.
72 changes: 43 additions & 29 deletions lib/src/components/headers/calendar_page_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,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) Spacer(flex: 1),
Expanded(
flex: 3,
child: titleBuilder != null
? DefaultTextStyle.merge(
style: headerStyle.headerTextStyle,
Expand All @@ -143,20 +151,26 @@ class CalendarPageHeader extends StatelessWidget {
),
if (headerStyle.rightIconVisible &&
headerStyle.rightIconConfig != null)
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: 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,
),
),
),
),
if (headerStyle.rightIconConfig == null) Spacer(flex: 1),
],
),
);
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 @@ -247,6 +247,8 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {

late VoidCallback _reloadCallback;

late HeaderStyle headerStyle;

@override
void initState() {
super.initState();
Expand All @@ -262,7 +264,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 @@ -513,11 +515,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 @@ -540,7 +554,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
14 changes: 14 additions & 0 deletions lib/src/week_view/week_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,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 @@ -430,6 +431,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 @@ -902,11 +904,23 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
_currentEndDate = _currentStartDate
.add(Duration(days: widget.showThreeDaysView ? 2 : 6));
_currentIndex = index;
_updateHeaderIcons();
});
}
widget.onPageChange?.call(_currentStartDate, _currentIndex);
}

// Hide header icons if end dates are reached
void _updateHeaderIcons() {
bool setLeftIconToNull = _currentStartDate == _minDate;
bool setRightIconToNull = _currentStartDate == _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 d108fd2

Please sign in to comment.