From bf6a574499bebd2f3e23ff27c94e4ba6c87b9628 Mon Sep 17 00:00:00 2001 From: Jaimin Rana Date: Wed, 1 Nov 2023 16:48:54 +0530 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9BDay=20view=20auto=20scroll?= =?UTF-8?q?=20to=20initial=20duration=20when=20using=20[scrollOffset]=20&?= =?UTF-8?q?=20[startingDuration]=20#269.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++++++-- lib/src/day_view/day_view.dart | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 543e1f8a..e3180dfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# [1.0.5] (UnReleased) + +- Fixed issue related to auto scroll to initial duration for day + view-[#269](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/269) + # [1.0.4 - 9 Aug 2023](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.0.4) - Fixed @@ -8,10 +13,9 @@ Issue [#237 - DayView & MonthView layout issue in landscape mode](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/237) - Added Feature [#57 - Change default start hour in DayView](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/57) -- Fixed +- Fixed Issue [#225 - Unwanted space at top in DayView while using sliver](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/225) - # [1.0.3 - 3 Apr 2023](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.0.3) - Added diff --git a/lib/src/day_view/day_view.dart b/lib/src/day_view/day_view.dart index 73ef9bee..6ae8d333 100644 --- a/lib/src/day_view/day_view.dart +++ b/lib/src/day_view/day_view.dart @@ -145,8 +145,12 @@ class DayView extends StatefulWidget { /// Background colour of day view page. final Color? backgroundColor; - /// Scroll offset of day view page. - final double scrollOffset; + /// Defines initial offset of first page that will be displayed when + /// [DayView] is initialized. + /// + /// If [scrollOffset] is null then [startDuration] will be considered for + /// initial offset. + final double? scrollOffset; /// This method will be called when user taps on event tile. final CellTapCallback? onEventTap; @@ -184,7 +188,7 @@ class DayView extends StatefulWidget { final bool showHalfHours; - /// Duration from where default day view will be visible + /// It define the starting duration from where day view page will be visible /// By default it will be Duration(hours:0) final Duration startDuration; @@ -214,7 +218,7 @@ class DayView extends StatefulWidget { this.eventArranger, this.verticalLineOffset = 10, this.backgroundColor = Colors.white, - this.scrollOffset = 0.0, + this.scrollOffset, this.onEventTap, this.onDateLongPress, this.onDateTap, @@ -298,8 +302,9 @@ class DayViewState extends State> { _regulateCurrentDate(); _calculateHeights(); - _scrollController = - ScrollController(initialScrollOffset: widget.scrollOffset); + _scrollController = ScrollController( + initialScrollOffset: widget.scrollOffset ?? + widget.startDuration.inMinutes * widget.heightPerMinute); _pageController = PageController(initialPage: _currentIndex); _eventArranger = widget.eventArranger ?? SideEventArranger(); _assignBuilders(); @@ -323,10 +328,6 @@ class DayViewState extends State> { // user adds new events. ..addListener(_reloadCallback); } - - WidgetsBinding.instance.addPostFrameCallback((_) { - animateToDuration(widget.startDuration); - }); } @override @@ -799,8 +800,7 @@ class DayViewState extends State> { // above 24 hrs then we take it max as 24 hours only final offset = offSetForSingleMinute * (startDurationInMinutes > 3600 ? 3600 : startDurationInMinutes); - debugPrint("offSet $offset"); - _scrollController.animateTo( + animateTo( offset.toDouble(), duration: duration, curve: curve,