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
- hideDayNotInMonth added. It by default false. It set to true to hide date which not is in current month.
  • Loading branch information
ravilsimform authored and apurva010 committed May 8, 2024
1 parent 1770d66 commit aeb34f6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- # [1.1.1] (UnReleased)
- Fixed issue related to Hiding Day which not in 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 for horizontal scroll physics of week and month view page. [#314](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/314)
- Fixed issue related to the live time indicator is that it is not in the correct position when startHour is set for the week and day view. [#346](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/346)
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,
hideDayNotInMonth: false,
onEventTap: (event, date) {
Navigator.of(context).push(
MaterialPageRoute(
Expand Down
38 changes: 22 additions & 16 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 hideDayNotInMonth;

/// 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.hideDayNotInMonth = true,
this.shouldHighlight = false,
this.backgroundColor = Colors.blue,
this.highlightColor = Colors.blue,
Expand All @@ -133,22 +137,24 @@ 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,
),
),
),
(isInMonth == false && hideDayNotInMonth)
? SizedBox.shrink()
: 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 @@ -161,6 +161,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 hideDayNotInMonth;

/// Main [Widget] to display month view.
const MonthView({
Key? key,
Expand Down Expand Up @@ -194,6 +197,7 @@ class MonthView<T extends Object?> extends StatefulWidget {
this.pagePhysics = const ClampingScrollPhysics(),
this.pageViewPhysics,
this.onEventDoubleTap,
this.hideDayNotInMonth = false,
}) : assert(!(onHeaderTitleTap != null && headerBuilder != null),
"can't use [onHeaderTitleTap] & [headerBuilder] simultaneously"),
super(key: key);
Expand Down Expand Up @@ -375,6 +379,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
showBorder: widget.showBorder,
startDay: widget.startDay,
physics: widget.pagePhysics,
hideDayNotInMonth: widget.hideDayNotInMonth,
),
);
}),
Expand Down Expand Up @@ -526,7 +531,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,
hideDayNotInMonth,
) {
if (hideDayNotInMonth) {
return FilledCell<T>(
date: date,
shouldHighlight: isToday,
backgroundColor: isInMonth ? Constants.white : Constants.offWhite,
events: events,
isInMonth: isInMonth,
onTileTap: widget.onEventTap,
dateStringBuilder: widget.dateStringBuilder,
hideDayNotInMonth: hideDayNotInMonth,
);
}
return FilledCell<T>(
date: date,
shouldHighlight: isToday,
Expand All @@ -536,6 +558,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
onTileLongTap: widget.onEventLongTap,
dateStringBuilder: widget.dateStringBuilder,
onTileDoubleTap: widget.onEventDoubleTap,
hideDayNotInMonth: hideDayNotInMonth,
);
}

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

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

@override
Expand Down Expand Up @@ -679,6 +704,7 @@ class _MonthPageBuilder<T> extends StatelessWidget {
events,
monthDays[index].compareWithoutTime(DateTime.now()),
monthDays[index].month == date.month,
hideDayNotInMonth,
),
),
);
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 hideDayNotInMonth,
);

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

0 comments on commit aeb34f6

Please sign in to comment.