Skip to content

Commit

Permalink
feat: ✨add showWeekends flag in month view #385
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-jitiya-simform committed Nov 29, 2024
1 parent cc99a0e commit 25a1a74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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,
showWeekends: false,
hideDaysNotInMonth: false,
onEventTap: (event, date) {
Navigator.of(context).push(
Expand Down
13 changes: 11 additions & 2 deletions lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class MonthView<T extends Object?> extends StatefulWidget {
/// This method will be called when user double taps on event tile.
final TileTapCallback<T>? onEventDoubleTap;

/// Show weekends or not
///
/// Default value is true.
final bool showWeekends;

/// Builds the name of the weeks.
///
/// Used default week builder if null.
Expand Down Expand Up @@ -184,6 +189,7 @@ class MonthView<T extends Object?> extends StatefulWidget {
this.maxMonth,
this.controller,
this.initialMonth,
this.showWeekends = true,
this.borderSize = 1,
this.useAvailableVerticalSpace = false,
this.cellAspectRatio = 0.55,
Expand Down Expand Up @@ -352,7 +358,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
width: _width,
child: Row(
children: List.generate(
7,
widget.showWeekends ? 7 : 5,
(index) => Expanded(
child: SizedBox(
width: _cellWidth,
Expand Down Expand Up @@ -391,6 +397,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
startDay: widget.startDay,
physics: widget.pagePhysics,
hideDaysNotInMonth: widget.hideDaysNotInMonth,
dayCount: widget.showWeekends ? 7 : 5,
),
);
}),
Expand Down Expand Up @@ -663,6 +670,7 @@ class _MonthPageBuilder<T> extends StatelessWidget {
final WeekDays startDay;
final ScrollPhysics physics;
final bool hideDaysNotInMonth;
final int dayCount;

const _MonthPageBuilder({
Key? key,
Expand All @@ -680,6 +688,7 @@ class _MonthPageBuilder<T> extends StatelessWidget {
required this.startDay,
required this.physics,
required this.hideDaysNotInMonth,
required this.dayCount,
}) : super(key: key);

@override
Expand All @@ -692,7 +701,7 @@ class _MonthPageBuilder<T> extends StatelessWidget {
padding: EdgeInsets.zero,
physics: physics,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 7,
crossAxisCount: dayCount,
childAspectRatio: cellRatio,
),
itemCount: 42,
Expand Down

0 comments on commit 25a1a74

Please sign in to comment.