Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛hide month days not in current month functionality added #328. #334

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
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
8 changes: 7 additions & 1 deletion lib/src/components/month_view_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,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 @@ -125,7 +129,9 @@ class FilledCell<T extends Object?> extends StatelessWidget {
SizedBox(
height: 5.0,
),
CircleAvatar(
(isInMonth == false && hideDayNotInMonth)
? SizedBox.shrink()
: CircleAvatar(
radius: highlightRadius,
backgroundColor:
shouldHighlight ? highlightColor : Colors.transparent,
Expand Down
23 changes: 22 additions & 1 deletion lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ class MonthView<T extends Object?> 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,
Expand Down Expand Up @@ -177,6 +180,7 @@ class MonthView<T extends Object?> 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);
Expand Down Expand Up @@ -357,6 +361,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 @@ -508,14 +513,27 @@ 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,
backgroundColor: isInMonth ? Constants.white : Constants.offWhite,
events: events,
onTileTap: widget.onEventTap,
dateStringBuilder: widget.dateStringBuilder,
hideDayNotInMonth: hideDayNotInMonth,
);
}

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

const _MonthPageBuilder({
Key? key,
Expand All @@ -623,6 +642,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 @@ -659,6 +679,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
Loading