diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a5ccbda..630bfc14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index 206f5c09..7f76f072 100644 --- a/README.md +++ b/README.md @@ -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 ); ``` diff --git a/example/lib/widgets/month_view_widget.dart b/example/lib/widgets/month_view_widget.dart index f0aa051c..bacec7eb 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, + hideDaysNotInMonth: 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..dd32755c 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 hideDaysNotInMonth; + /// 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.hideDaysNotInMonth = true, this.shouldHighlight = false, this.backgroundColor = Colors.blue, this.highlightColor = Colors.blue, @@ -133,22 +137,23 @@ 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, + 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( diff --git a/lib/src/month_view/month_view.dart b/lib/src/month_view/month_view.dart index 3f974e71..236fb73e 100644 --- a/lib/src/month_view/month_view.dart +++ b/lib/src/month_view/month_view.dart @@ -167,6 +167,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 hideDaysNotInMonth; + /// Main [Widget] to display month view. const MonthView({ Key? key, @@ -201,6 +204,7 @@ class MonthView 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); @@ -382,6 +386,7 @@ class MonthViewState extends State> { showBorder: widget.showBorder, startDay: widget.startDay, physics: widget.pagePhysics, + hideDaysNotInMonth: widget.hideDaysNotInMonth, ), ); }), @@ -534,7 +539,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, + hideDaysNotInMonth, + ) { + if (hideDaysNotInMonth) { + return FilledCell( + date: date, + shouldHighlight: isToday, + backgroundColor: isInMonth ? Constants.white : Constants.offWhite, + events: events, + isInMonth: isInMonth, + onTileTap: widget.onEventTap, + dateStringBuilder: widget.dateStringBuilder, + hideDaysNotInMonth: hideDaysNotInMonth, + ); + } return FilledCell( date: date, shouldHighlight: isToday, @@ -544,6 +566,7 @@ class MonthViewState extends State> { onTileLongTap: widget.onEventLongTap, dateStringBuilder: widget.dateStringBuilder, onTileDoubleTap: widget.onEventDoubleTap, + hideDaysNotInMonth: hideDaysNotInMonth, ); } @@ -635,6 +658,7 @@ class _MonthPageBuilder extends StatelessWidget { final DatePressCallback? onDateLongPress; final WeekDays startDay; final ScrollPhysics physics; + final bool hideDaysNotInMonth; const _MonthPageBuilder({ Key? key, @@ -651,6 +675,7 @@ class _MonthPageBuilder extends StatelessWidget { required this.onDateLongPress, required this.startDay, required this.physics, + required this.hideDaysNotInMonth, }) : super(key: key); @override @@ -687,6 +712,7 @@ class _MonthPageBuilder extends StatelessWidget { events, monthDays[index].compareWithoutTime(DateTime.now()), monthDays[index].month == date.month, + hideDaysNotInMonth, ), ), ); diff --git a/lib/src/typedefs.dart b/lib/src/typedefs.dart index 35151b86..d966ac0c 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 hideDaysNotInMonth, ); typedef EventTileBuilder = Widget Function(