From baeb4975ca045210a2a69458ec2474c6135b382d Mon Sep 17 00:00:00 2001 From: FineFindus <63370021+FineFindus@users.noreply.github.com> Date: Thu, 15 Apr 2021 12:22:33 +0200 Subject: [PATCH] added animatedPageScrolling option --- example/lib/pages/basics_example.dart | 1 - lib/src/table_calendar.dart | 9 +++++++-- lib/src/table_calendar_base.dart | 12 +++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/example/lib/pages/basics_example.dart b/example/lib/pages/basics_example.dart index 156118b0..6a8f91b6 100644 --- a/example/lib/pages/basics_example.dart +++ b/example/lib/pages/basics_example.dart @@ -27,7 +27,6 @@ class _TableBasicsExampleState extends State { 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. diff --git a/lib/src/table_calendar.dart b/lib/src/table_calendar.dart index bf14a594..0149cf34 100644 --- a/lib/src/table_calendar.dart +++ b/lib/src/table_calendar.dart @@ -94,6 +94,9 @@ class TableCalendar 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; @@ -107,12 +110,12 @@ class TableCalendar 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; @@ -217,6 +220,7 @@ class TableCalendar 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), @@ -484,6 +488,7 @@ class _TableCalendarState extends State> { rowHeight: widget.rowHeight, formatAnimationDuration: widget.formatAnimationDuration, formatAnimationCurve: widget.formatAnimationCurve, + animatedPageScrolling: widget.animatedPageScrolling, pageChangeAnimationDuration: widget.pageAnimationDuration, pageChangeAnimationCurve: widget.pageAnimationCurve, availableCalendarFormats: widget.availableCalendarFormats, diff --git a/lib/src/table_calendar_base.dart b/lib/src/table_calendar_base.dart index ed7ba4f9..e37e16d8 100644 --- a/lib/src/table_calendar_base.dart +++ b/lib/src/table_calendar_base.dart @@ -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; @@ -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, @@ -151,9 +153,13 @@ class _TableCalendarBaseState extends State 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; }