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 6, 2025
1 parent 501bdb5 commit cf7f28c
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 34 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
83 changes: 50 additions & 33 deletions lib/src/components/headers/calendar_page_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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,
),
),
),
],
),
);
Expand Down
5 changes: 5 additions & 0 deletions lib/src/components/headers/day_page_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/components/headers/month_page_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/components/headers/week_page_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,15 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
/// [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) {
Expand Down Expand Up @@ -764,6 +769,18 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
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
Expand Down
6 changes: 5 additions & 1 deletion lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {

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

_assignBuilders();
}

Expand Down Expand Up @@ -521,7 +520,12 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {

/// 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);
Expand Down
6 changes: 6 additions & 0 deletions lib/src/week_view/week_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -832,11 +832,17 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
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);
Expand Down

0 comments on commit cf7f28c

Please sign in to comment.