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

Add displayDaysNumber #728

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions lib/src/table_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ class TableCalendar<T> extends StatefulWidget {
/// * `RangeSelectionMode.enforced` - range selection is always on.
final RangeSelectionMode rangeSelectionMode;

/// List of display days Number
/// eg. Starting Days is Monday and displayDaysNumber is 5 -> Mon, Tue, Wed, Thu, Fri
/// eg. Starting Days is Sunday and displayDaysNumber is 3 -> Sun, Mon, Tue, Wed
final int displayDaysNumber;

/// Function that assigns a list of events to a specified day.
final List<T> Function(DateTime day)? eventLoader;

Expand Down Expand Up @@ -246,6 +251,7 @@ class TableCalendar<T> extends StatefulWidget {
this.calendarStyle = const CalendarStyle(),
this.calendarBuilders = const CalendarBuilders(),
this.rangeSelectionMode = RangeSelectionMode.toggledOff,
this.displayDaysNumber = 7,
this.eventLoader,
this.enabledDayPredicate,
this.selectedDayPredicate,
Expand Down Expand Up @@ -508,6 +514,7 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> {
_focusedDay.value = focusedDay;
widget.onPageChanged?.call(focusedDay);
},
displayDaysNumber: widget.displayDaysNumber,
weekNumbersVisible: widget.weekNumbersVisible,
weekNumberBuilder: (BuildContext context, DateTime day) {
final weekNumber = _calculateWeekNumber(day);
Expand Down
3 changes: 3 additions & 0 deletions lib/src/table_calendar_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class TableCalendarBase extends StatefulWidget {
final SwipeCallback? onVerticalSwipe;
final void Function(DateTime focusedDay)? onPageChanged;
final void Function(PageController pageController)? onCalendarCreated;
final int displayDaysNumber;

TableCalendarBase({
Key? key,
Expand Down Expand Up @@ -72,6 +73,7 @@ class TableCalendarBase extends StatefulWidget {
this.onVerticalSwipe,
this.onPageChanged,
this.onCalendarCreated,
this.displayDaysNumber=7,
}) : assert(!dowVisible || (dowHeight != null && dowBuilder != null)),
assert(isSameDay(focusedDay, firstDay) || focusedDay.isAfter(firstDay)),
assert(isSameDay(focusedDay, lastDay) || focusedDay.isBefore(lastDay)),
Expand Down Expand Up @@ -204,6 +206,7 @@ class _TableCalendarBaseState extends State<TableCalendarBase> {
);
},
child: CalendarCore(
displayDaysNumber: widget.displayDaysNumber,
constraints: constraints,
pageController: _pageController,
scrollPhysics: _canScrollHorizontally
Expand Down
3 changes: 3 additions & 0 deletions lib/src/widgets/calendar_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CalendarCore extends StatelessWidget {
final PageController? pageController;
final ScrollPhysics? scrollPhysics;
final _OnCalendarPageChanged onPageChanged;
final int displayDaysNumber;

const CalendarCore({
Key? key,
Expand All @@ -55,6 +56,7 @@ class CalendarCore extends StatelessWidget {
this.rowDecoration,
this.tableBorder,
this.scrollPhysics,
this.displayDaysNumber = 7,
}) : assert(!dowVisible || (dowHeight != null && dowBuilder != null)),
super(key: key);

Expand Down Expand Up @@ -110,6 +112,7 @@ class CalendarCore extends StatelessWidget {
child: weekNumberBuilder?.call(context, day),
);
},
displayDaysNumber: displayDaysNumber,
);
},
onPageChanged: (index) {
Expand Down
6 changes: 4 additions & 2 deletions lib/src/widgets/calendar_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CalendarPage extends StatelessWidget {
final bool dowVisible;
final bool weekNumberVisible;
final double? dowHeight;
final int displayDaysNumber;

const CalendarPage({
Key? key,
Expand All @@ -27,6 +28,7 @@ class CalendarPage extends StatelessWidget {
this.dowVisible = true,
this.weekNumberVisible = false,
this.dowHeight,
this.displayDaysNumber = 7,
}) : assert(!dowVisible || (dowHeight != null && dowBuilder != null)),
assert(!weekNumberVisible || weekNumberBuilder != null),
super(key: key);
Expand Down Expand Up @@ -66,7 +68,7 @@ class CalendarPage extends StatelessWidget {
return TableRow(
decoration: dowDecoration,
children: List.generate(
7,
displayDaysNumber,
(index) => dowBuilder!(context, visibleDays[index]),
).toList(),
);
Expand All @@ -79,7 +81,7 @@ class CalendarPage extends StatelessWidget {
.map((index) => TableRow(
decoration: rowDecoration,
children: List.generate(
7,
displayDaysNumber,
(id) => dayBuilder(context, visibleDays[index + id]),
),
))
Expand Down