Skip to content

Commit

Permalink
fix: 🐛hide month days not in current month functionality added #328. (#…
Browse files Browse the repository at this point in the history
…362)

- hideDayNotInMonth added. It by default false. It set to true to hide date which not is in current month.

Co-authored-by: Ravi <[email protected]>
  • Loading branch information
apurva010 and ravilsimform authored May 8, 2024
1 parent 407f187 commit 416387f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- # [1.1.1] (UnReleased)
- Added showWeekTileBorder field whether to show border for header in month view. [#306](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/306)
- Fixed an issue related to hiding day, which is not in the current month in MonthView. [#328](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/328)
- Added support for double tapping gestures on any event in day, week, and month view. [#195](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/195)
- Added support to set end time of day and week view. [#298](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/298)
- Added support for horizontal scroll physics of week and month view page. [#314](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/314)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ MonthView(
onDateLongPress: (date) => print(date),
headerBuilder: MonthHeader.hidden, // To hide month header
showWeekTileBorder: false, // To show or hide header border
hideDaysNotInMonth: true, // To hide days or cell that are not in current month
);
```

Expand Down
1 change: 1 addition & 0 deletions example/lib/widgets/month_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MonthViewWidget extends StatelessWidget {
return MonthView(
key: state,
width: width,
hideDaysNotInMonth: false,
onEventTap: (event, date) {
Navigator.of(context).push(
MaterialPageRoute(
Expand Down
33 changes: 19 additions & 14 deletions lib/src/components/month_view_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,17 @@ class FilledCell<T extends Object?> extends StatelessWidget {
/// color of highlighted cell title
final Color highlightedTitleColor;

/// defines that show and hide cell not is in current month
final bool hideDaysNotInMonth;

/// This class will defines how cell will be displayed.
/// This widget will display all the events as tile below date title.
const FilledCell({
Key? key,
required this.date,
required this.events,
this.isInMonth = false,
this.hideDaysNotInMonth = true,
this.shouldHighlight = false,
this.backgroundColor = Colors.blue,
this.highlightColor = Colors.blue,
Expand All @@ -133,22 +137,23 @@ class FilledCell<T extends Object?> extends StatelessWidget {
SizedBox(
height: 5.0,
),
CircleAvatar(
radius: highlightRadius,
backgroundColor:
shouldHighlight ? highlightColor : Colors.transparent,
child: Text(
dateStringBuilder?.call(date) ?? "${date.day}",
style: TextStyle(
color: shouldHighlight
? highlightedTitleColor
: isInMonth
? titleColor
: titleColor.withOpacity(0.4),
fontSize: 12,
if (!(!isInMonth && hideDaysNotInMonth))
CircleAvatar(
radius: highlightRadius,
backgroundColor:
shouldHighlight ? highlightColor : Colors.transparent,
child: Text(
dateStringBuilder?.call(date) ?? "${date.day}",
style: TextStyle(
color: shouldHighlight
? highlightedTitleColor
: isInMonth
? titleColor
: titleColor.withOpacity(0.4),
fontSize: 12,
),
),
),
),
if (events.isNotEmpty)
Expanded(
child: Container(
Expand Down
28 changes: 27 additions & 1 deletion lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ class MonthView<T extends Object?> extends StatefulWidget {
/// This can be used to disable the horizontal scroll of a page.
final ScrollPhysics? pageViewPhysics;

/// defines that show and hide cell not is in current month
final bool hideDaysNotInMonth;

/// Main [Widget] to display month view.
const MonthView({
Key? key,
Expand Down Expand Up @@ -201,6 +204,7 @@ class MonthView<T extends Object?> extends StatefulWidget {
this.pageViewPhysics,
this.onEventDoubleTap,
this.showWeekTileBorder = true,
this.hideDaysNotInMonth = false,
}) : assert(!(onHeaderTitleTap != null && headerBuilder != null),
"can't use [onHeaderTitleTap] & [headerBuilder] simultaneously"),
super(key: key);
Expand Down Expand Up @@ -382,6 +386,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
showBorder: widget.showBorder,
startDay: widget.startDay,
physics: widget.pagePhysics,
hideDaysNotInMonth: widget.hideDaysNotInMonth,
),
);
}),
Expand Down Expand Up @@ -534,7 +539,24 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {

/// Default cell builder. Used when [widget.cellBuilder] is null
Widget _defaultCellBuilder(
date, List<CalendarEventData<T>> events, isToday, isInMonth) {
date,
List<CalendarEventData<T>> events,
isToday,
isInMonth,
hideDaysNotInMonth,
) {
if (hideDaysNotInMonth) {
return FilledCell<T>(
date: date,
shouldHighlight: isToday,
backgroundColor: isInMonth ? Constants.white : Constants.offWhite,
events: events,
isInMonth: isInMonth,
onTileTap: widget.onEventTap,
dateStringBuilder: widget.dateStringBuilder,
hideDaysNotInMonth: hideDaysNotInMonth,
);
}
return FilledCell<T>(
date: date,
shouldHighlight: isToday,
Expand All @@ -544,6 +566,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
onTileLongTap: widget.onEventLongTap,
dateStringBuilder: widget.dateStringBuilder,
onTileDoubleTap: widget.onEventDoubleTap,
hideDaysNotInMonth: hideDaysNotInMonth,
);
}

Expand Down Expand Up @@ -635,6 +658,7 @@ class _MonthPageBuilder<T> extends StatelessWidget {
final DatePressCallback? onDateLongPress;
final WeekDays startDay;
final ScrollPhysics physics;
final bool hideDaysNotInMonth;

const _MonthPageBuilder({
Key? key,
Expand All @@ -651,6 +675,7 @@ class _MonthPageBuilder<T> extends StatelessWidget {
required this.onDateLongPress,
required this.startDay,
required this.physics,
required this.hideDaysNotInMonth,
}) : super(key: key);

@override
Expand Down Expand Up @@ -687,6 +712,7 @@ class _MonthPageBuilder<T> extends StatelessWidget {
events,
monthDays[index].compareWithoutTime(DateTime.now()),
monthDays[index].month == date.month,
hideDaysNotInMonth,
),
),
);
Expand Down
1 change: 1 addition & 0 deletions lib/src/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ typedef CellBuilder<T extends Object?> = Widget Function(
List<CalendarEventData<T>> event,
bool isToday,
bool isInMonth,
bool hideDaysNotInMonth,
);

typedef EventTileBuilder<T extends Object?> = Widget Function(
Expand Down

0 comments on commit 416387f

Please sign in to comment.