From a372c08720f10a48cbb2134e9cd1e4b310adb85b 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 | 8 ++++++- lib/src/month_view/month_view.dart | 23 ++++++++++++++++++- lib/src/typedefs.dart | 1 + 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 362501ac..4292b812 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # [1.1.0 - 28 Feb 2024](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.1.0) +- Fixed issue related to Hiding Day which not in current month in MonthView. [#328](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/328) - Fixed issue related to Hiding Header [#299](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/pull/299) - Fixed issue related to auto scroll to initial duration for day view. [#269](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/269) diff --git a/example/lib/widgets/month_view_widget.dart b/example/lib/widgets/month_view_widget.dart index 9f287382..ce0ac9aa 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 57ae6796..4e4929cc 100644 --- a/lib/src/components/month_view_components.dart +++ b/lib/src/components/month_view_components.dart @@ -98,6 +98,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({ @@ -105,6 +108,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, @@ -125,7 +129,9 @@ class FilledCell extends StatelessWidget { SizedBox( height: 5.0, ), - CircleAvatar( + (isInMonth == false && hideDayNotInMonth) + ? SizedBox.shrink() + : CircleAvatar( radius: highlightRadius, backgroundColor: shouldHighlight ? highlightColor : Colors.transparent, diff --git a/lib/src/month_view/month_view.dart b/lib/src/month_view/month_view.dart index f0a0b65d..bb08f75a 100644 --- a/lib/src/month_view/month_view.dart +++ b/lib/src/month_view/month_view.dart @@ -147,6 +147,9 @@ class MonthView extends StatefulWidget { /// Default value is [ClampingScrollPhysics]. final ScrollPhysics pagePhysics; + /// defines that show and hide cell not is in current month + final bool hideDayNotInMonth; + /// Main [Widget] to display month view. const MonthView({ Key? key, @@ -177,6 +180,7 @@ class MonthView extends StatefulWidget { this.safeAreaOption = const SafeAreaOption(), this.onHeaderTitleTap, this.pagePhysics = const ClampingScrollPhysics(), + this.hideDayNotInMonth = false }) : assert(!(onHeaderTitleTap != null && headerBuilder != null), "can't use [onHeaderTitleTap] & [headerBuilder] simultaneously"), super(key: key); @@ -357,6 +361,7 @@ class MonthViewState extends State> { showBorder: widget.showBorder, startDay: widget.startDay, physics: widget.pagePhysics, + hideDayNotInMonth: widget.hideDayNotInMonth, ), ); }), @@ -508,7 +513,19 @@ 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, @@ -516,6 +533,7 @@ class MonthViewState extends State> { events: events, onTileTap: widget.onEventTap, dateStringBuilder: widget.dateStringBuilder, + hideDayNotInMonth: hideDayNotInMonth, ); } @@ -607,6 +625,7 @@ class _MonthPageBuilder extends StatelessWidget { final DatePressCallback? onDateLongPress; final WeekDays startDay; final ScrollPhysics physics; + final bool hideDayNotInMonth; const _MonthPageBuilder({ Key? key, @@ -623,6 +642,7 @@ class _MonthPageBuilder extends StatelessWidget { required this.onDateLongPress, required this.startDay, required this.physics, + required this.hideDayNotInMonth, }) : super(key: key); @override @@ -659,6 +679,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(