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 2e994ba
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 31 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
85 changes: 54 additions & 31 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;

/// Hide & show right icon
final bool showNextIcon;

/// When user taps on left arrow.
///
/// This will be ignored if left icon is provided in [headerStyle].
final VoidCallback? onPreviousDay;

/// Hide & show left icon
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 @@ -104,22 +112,29 @@ 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,
),
),
AbsorbPointer(
absorbing: !showPreviousIcon,
child: 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 @@ -142,21 +157,29 @@ class CalendarPageHeader extends StatelessWidget {
),
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,
),
),
AbsorbPointer(
absorbing: !showNextIcon,
child: 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
5 changes: 5 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 != _minDate;
final showRightIcon = date != _maxDate;

return DayPageHeader(
date: _currentDate,
dateStringBuilder: widget.dateStringBuilder,
onNextDay: nextPage,
showPreviousIcon: showLeftIcon,
showNextIcon: showRightIcon,
onPreviousDay: previousPage,
onTitleTapped: () async {
if (widget.onHeaderTitleTap != null) {
Expand Down
5 changes: 5 additions & 0 deletions lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,12 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {

/// Default month view header builder
Widget _defaultHeaderBuilder(DateTime date) {
final showLeftIcon = date != _minDate;
final showRightIcon = date != _maxDate;

return MonthPageHeader(
showPreviousIcon: showLeftIcon,
showNextIcon: showRightIcon,
onTitleTapped: () async {
if (widget.onHeaderTitleTap != null) {
widget.onHeaderTitleTap!(date);
Expand Down
5 changes: 5 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,16 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
DateTime startDate,
DateTime endDate,
) {
final showLeftIcon = startDate != _minDate;
final showRightIcon = endDate != _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 2e994ba

Please sign in to comment.