From aeb34f67ffb31bdd876c76447de705ecd072f82e Mon Sep 17 00:00:00 2001 From: Ravi Date: Mon, 18 Mar 2024 17:14:53 +0530 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9Bhide=20month=20days=20not=20?= =?UTF-8?q?in=20current=20month=20functionality=20added=20#328.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - hideDayNotInMonth added. It by default false. It set to true to hide date which not is in current month. --- CHANGELOG.md | 1 + example/lib/widgets/month_view_widget.dart | 1 + lib/src/components/month_view_components.dart | 38 +++++++++++-------- lib/src/month_view/month_view.dart | 28 +++++++++++++- lib/src/typedefs.dart | 1 + 5 files changed, 52 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2c885f7..eb795f0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/example/lib/widgets/month_view_widget.dart b/example/lib/widgets/month_view_widget.dart index f0aa051c..de8f075e 100644 --- a/example/lib/widgets/month_view_widget.dart +++ b/example/lib/widgets/month_view_widget.dart @@ -18,6 +18,7 @@ class MonthViewWidget extends StatelessWidget { return MonthView( key: state, width: width, + hideDayNotInMonth: false, onEventTap: (event, date) { Navigator.of(context).push( MaterialPageRoute( diff --git a/lib/src/components/month_view_components.dart b/lib/src/components/month_view_components.dart index 33f00993..5215ca6b 100644 --- a/lib/src/components/month_view_components.dart +++ b/lib/src/components/month_view_components.dart @@ -104,6 +104,9 @@ class FilledCell 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({ @@ -111,6 +114,7 @@ class FilledCell extends StatelessWidget { required this.date, required this.events, this.isInMonth = false, + this.hideDayNotInMonth = true, this.shouldHighlight = false, this.backgroundColor = Colors.blue, this.highlightColor = Colors.blue, @@ -133,22 +137,24 @@ class FilledCell 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( diff --git a/lib/src/month_view/month_view.dart b/lib/src/month_view/month_view.dart index 4c62e989..86fa34e1 100644 --- a/lib/src/month_view/month_view.dart +++ b/lib/src/month_view/month_view.dart @@ -161,6 +161,9 @@ class MonthView 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, @@ -194,6 +197,7 @@ class MonthView 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); @@ -375,6 +379,7 @@ class MonthViewState extends State> { showBorder: widget.showBorder, startDay: widget.startDay, physics: widget.pagePhysics, + hideDayNotInMonth: widget.hideDayNotInMonth, ), ); }), @@ -526,7 +531,24 @@ class MonthViewState extends State> { /// Default cell builder. Used when [widget.cellBuilder] is null Widget _defaultCellBuilder( - date, List> events, isToday, isInMonth) { + date, + List> events, + isToday, + isInMonth, + hideDayNotInMonth, + ) { + if (hideDayNotInMonth) { + return FilledCell( + date: date, + shouldHighlight: isToday, + backgroundColor: isInMonth ? Constants.white : Constants.offWhite, + events: events, + isInMonth: isInMonth, + onTileTap: widget.onEventTap, + dateStringBuilder: widget.dateStringBuilder, + hideDayNotInMonth: hideDayNotInMonth, + ); + } return FilledCell( date: date, shouldHighlight: isToday, @@ -536,6 +558,7 @@ class MonthViewState extends State> { onTileLongTap: widget.onEventLongTap, dateStringBuilder: widget.dateStringBuilder, onTileDoubleTap: widget.onEventDoubleTap, + hideDayNotInMonth: hideDayNotInMonth, ); } @@ -627,6 +650,7 @@ class _MonthPageBuilder extends StatelessWidget { final DatePressCallback? onDateLongPress; final WeekDays startDay; final ScrollPhysics physics; + final bool hideDayNotInMonth; const _MonthPageBuilder({ Key? key, @@ -643,6 +667,7 @@ class _MonthPageBuilder extends StatelessWidget { required this.onDateLongPress, required this.startDay, required this.physics, + required this.hideDayNotInMonth, }) : super(key: key); @override @@ -679,6 +704,7 @@ class _MonthPageBuilder extends StatelessWidget { events, monthDays[index].compareWithoutTime(DateTime.now()), monthDays[index].month == date.month, + hideDayNotInMonth, ), ), ); diff --git a/lib/src/typedefs.dart b/lib/src/typedefs.dart index cb39db36..f304a1d0 100644 --- a/lib/src/typedefs.dart +++ b/lib/src/typedefs.dart @@ -11,6 +11,7 @@ typedef CellBuilder = Widget Function( List> event, bool isToday, bool isInMonth, + bool hideDayNotInMonth, ); typedef EventTileBuilder = Widget Function(