Skip to content

Commit

Permalink
added animatedPageScrolling option
Browse files Browse the repository at this point in the history
  • Loading branch information
FineFindus committed Apr 15, 2021
1 parent c40ed7a commit baeb497
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 0 additions & 1 deletion example/lib/pages/basics_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class _TableBasicsExampleState extends State<TableBasicsExample> {
lastDay: kLastDay,
focusedDay: _focusedDay,
calendarFormat: _calendarFormat,
pageJumpingEnabled: true,
selectedDayPredicate: (day) {
// Use `selectedDayPredicate` to determine which day is currently selected.
// If this returns true, then `day` will be marked as selected.
Expand Down
9 changes: 7 additions & 2 deletions lib/src/table_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class TableCalendar<T> extends StatefulWidget {
/// When set to true, `TableCalendar` will fill available height.
final bool shouldFillViewport;

/// When set to true, an animation is displayed when changing the visible month.
final bool animatedPageScrolling;

/// Used for setting the height of `TableCalendar`'s rows.
final double rowHeight;

Expand All @@ -107,12 +110,12 @@ class TableCalendar<T> extends StatefulWidget {
final Curve formatAnimationCurve;

/// Specifies the duration of page change animation that takes place when the visible month changes,
/// either by tapping the left or right chevron or when `pageJumpingEnabled` is set to true and
/// either by tapping the left or right chevron or when `pageJumpingEnabled` and `animatedPageScrolling` are set to true and
/// the user clicks outside of a month.
final Duration pageAnimationDuration;

/// Specifies the curve of page change animation that takes place when the visible month changes,
/// either by tapping the left or right chevron or when `pageJumpingEnabled` is set to true and
/// either by tapping the left or right chevron or when `pageJumpingEnabled` and `animatedPageScrolling` are set to true and
/// the user clicks outside of a month.
final Curve pageAnimationCurve;

Expand Down Expand Up @@ -217,6 +220,7 @@ class TableCalendar<T> extends StatefulWidget {
this.pageJumpingEnabled = false,
this.sixWeekMonthsEnforced = false,
this.shouldFillViewport = false,
this.animatedPageScrolling = false,
this.rowHeight = 52.0,
this.daysOfWeekHeight = 16.0,
this.formatAnimationDuration = const Duration(milliseconds: 200),
Expand Down Expand Up @@ -484,6 +488,7 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> {
rowHeight: widget.rowHeight,
formatAnimationDuration: widget.formatAnimationDuration,
formatAnimationCurve: widget.formatAnimationCurve,
animatedPageScrolling: widget.animatedPageScrolling,
pageChangeAnimationDuration: widget.pageAnimationDuration,
pageChangeAnimationCurve: widget.pageAnimationCurve,
availableCalendarFormats: widget.availableCalendarFormats,
Expand Down
12 changes: 9 additions & 3 deletions lib/src/table_calendar_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TableCalendarBase extends StatefulWidget {
final Decoration? rowDecoration;
final Duration formatAnimationDuration;
final Curve formatAnimationCurve;
final bool animatedPageScrolling;
final Duration pageChangeAnimationDuration;
final Curve pageChangeAnimationCurve;
final StartingDayOfWeek startingDayOfWeek;
Expand All @@ -48,6 +49,7 @@ class TableCalendarBase extends StatefulWidget {
this.rowDecoration,
this.formatAnimationDuration = const Duration(milliseconds: 200),
this.formatAnimationCurve = Curves.linear,
this.animatedPageScrolling = false,
this.pageChangeAnimationDuration = const Duration(milliseconds: 200),
this.pageChangeAnimationCurve = Curves.linear,
this.startingDayOfWeek = StartingDayOfWeek.sunday,
Expand Down Expand Up @@ -151,9 +153,13 @@ class _TableCalendarBaseState extends State<TableCalendarBase>
final rowCount = _getRowCount(widget.calendarFormat, _focusedDay);
_pageHeight.value = _getPageHeight(rowCount);

_pageController.animateToPage(currentIndex,
duration: widget.pageChangeAnimationDuration,
curve: widget.pageChangeAnimationCurve);
if (widget.animatedPageScrolling) {
_pageController.animateToPage(currentIndex,
duration: widget.pageChangeAnimationDuration,
curve: widget.pageChangeAnimationCurve);
} else {
_pageController.jumpToPage(currentIndex);
}
_pageCallbackDisabled = false;
}

Expand Down

0 comments on commit baeb497

Please sign in to comment.