diff --git a/lib/src/day_view/_internal_day_view_page.dart b/lib/src/day_view/_internal_day_view_page.dart index d7c9607e..cf37908d 100644 --- a/lib/src/day_view/_internal_day_view_page.dart +++ b/lib/src/day_view/_internal_day_view_page.dart @@ -14,7 +14,7 @@ import '../painters.dart'; import '../typedefs.dart'; /// Defines a single day page. -class InternalDayViewPage extends StatelessWidget { +class InternalDayViewPage extends StatefulWidget { /// Width of the page final double width; @@ -116,7 +116,10 @@ class InternalDayViewPage extends StatelessWidget { /// Settings for half hour indicator lines. final HourIndicatorSettings quarterHourIndicatorSettings; - final ScrollController scrollController; + final void Function(ScrollController) scrollListener; + + /// Scroll offset of day view page. + final double scrollOffset; /// Emulate vertical line offset from hour line starts. final double emulateVerticalOffsetBy; @@ -151,7 +154,8 @@ class InternalDayViewPage extends StatelessWidget { required this.minuteSlotSize, required this.scrollNotifier, required this.fullDayEventBuilder, - required this.scrollController, + required this.scrollListener, + this.scrollOffset = 0.0, required this.dayDetectorBuilder, required this.showHalfHours, required this.showQuarterHours, @@ -163,34 +167,67 @@ class InternalDayViewPage extends StatelessWidget { required this.onTileDoubleTap, }) : super(key: key); + @override + State createState() => _InternalDayViewPageState(); +} + +class _InternalDayViewPageState + extends State> { + late ScrollController scrollController; + + @override + void initState() { + super.initState(); + scrollController = ScrollController( + initialScrollOffset: widget.scrollOffset, + ); + scrollController.addListener(_scrollControllerListener); + } + + @override + void dispose() { + scrollController + ..removeListener(_scrollControllerListener) + ..dispose(); + super.dispose(); + } + + void _scrollControllerListener() { + widget.scrollListener(scrollController); + } + @override Widget build(BuildContext context) { final fullDayEventList = controller.getFullDayEvent(date); return Container( - height: height, - width: width, + height: widget.height, + width: widget.width, child: Column( children: [ fullDayEventList.isEmpty - ? SizedBox.shrink() - : fullDayEventBuilder(fullDayEventList, date), + ? SizedBox.shrink() + :widget.fullDayEventBuilder( + widget.controller.getFullDayEvent(widget.date), + widget.date, + ), Expanded( child: SingleChildScrollView( controller: scrollController, child: SizedBox( - height: height, - width: width, + height: widget.height, + width: widget.width, child: Stack( children: [ CustomPaint( - size: Size(width, height), + size: Size(widget.width, widget.height), painter: HourLinePainter( - lineColor: hourIndicatorSettings.color, - lineHeight: hourIndicatorSettings.height, - offset: timeLineWidth + hourIndicatorSettings.offset, - minuteHeight: heightPerMinute, - verticalLineOffset: verticalLineOffset, - showVerticalLine: showVerticalLine, + lineColor: widget.hourIndicatorSettings.color, + lineHeight: widget.hourIndicatorSettings.height, + offset: widget.timeLineWidth + + widget.hourIndicatorSettings.offset, + minuteHeight: widget.heightPerMinute, + verticalLineOffset: widget.verticalLineOffset, + showVerticalLine: widget.showVerticalLine, lineStyle: hourIndicatorSettings.lineStyle, dashWidth: hourIndicatorSettings.dashWidth, dashSpaceWidth: hourIndicatorSettings.dashSpaceWidth, @@ -241,48 +278,50 @@ class InternalDayViewPage extends StatelessWidget { Align( alignment: Alignment.centerRight, child: EventGenerator( - height: height, - date: date, + height: widget.height, + date: widget.date, onTileLongTap: onTileLongTap, onTileDoubleTap: onTileDoubleTap, - onTileTap: onTileTap, - eventArranger: eventArranger, - events: controller.getEventsOnDay( - date, + onTileTap: widget.onTileTap, + eventArranger: widget.eventArranger, + events: widget.controller.getEventsOnDay( + widget.date, includeFullDayEvents: false, ), - heightPerMinute: heightPerMinute, - eventTileBuilder: eventTileBuilder, - scrollNotifier: scrollNotifier, + heightPerMinute: widget.heightPerMinute, + eventTileBuilder: widget.eventTileBuilder, + scrollNotifier: widget.scrollNotifier, startHour: startHour, endHour: endHour, - width: width - - timeLineWidth - - hourIndicatorSettings.offset - - verticalLineOffset, + width: widget.width - + widget.timeLineWidth - + widget.hourIndicatorSettings.offset - + widget.verticalLineOffset, ), ), TimeLine( - height: height, - hourHeight: hourHeight, - timeLineBuilder: timeLineBuilder, - timeLineOffset: timeLineOffset, - timeLineWidth: timeLineWidth, + height: widget.height, + hourHeight: widget.hourHeight, + timeLineBuilder: widget.timeLineBuilder, + timeLineOffset: widget.timeLineOffset, + timeLineWidth: widget.timeLineWidth, showHalfHours: showHalfHours, startHour: startHour, endHour: endHour, showQuarterHours: showQuarterHours, - key: ValueKey(heightPerMinute), + key: ValueKey(widget.heightPerMinute), liveTimeIndicatorSettings: liveTimeIndicatorSettings, ), - if (showLiveLine && liveTimeIndicatorSettings.height > 0) + if (widget.showLiveLine && + widget.liveTimeIndicatorSettings.height > 0) IgnorePointer( child: LiveTimeIndicator( - liveTimeIndicatorSettings: liveTimeIndicatorSettings, - width: width, - height: height, - heightPerMinute: heightPerMinute, - timeLineWidth: timeLineWidth, + liveTimeIndicatorSettings: + widget.liveTimeIndicatorSettings, + width: widget.width, + height: widget.height, + heightPerMinute: widget.heightPerMinute, + timeLineWidth: widget.timeLineWidth, startHour: startHour, endHour: endHour, ), diff --git a/lib/src/day_view/day_view.dart b/lib/src/day_view/day_view.dart index 7f73c989..f2c14d83 100644 --- a/lib/src/day_view/day_view.dart +++ b/lib/src/day_view/day_view.dart @@ -309,6 +309,7 @@ class DayViewState extends State> { late double _height; late double _timeLineWidth; late double _hourHeight; + late double _lastScrollOffset; late DateTime _currentDate; late DateTime _maxDate; late DateTime _minDate; @@ -349,6 +350,7 @@ class DayViewState extends State> { @override void initState() { super.initState(); + _lastScrollOffset = widget.scrollOffset; _reloadCallback = _reload; _setDateRange(); @@ -484,7 +486,8 @@ class DayViewState extends State> { minuteSlotSize: widget.minuteSlotSize, scrollNotifier: _scrollConfiguration, fullDayEventBuilder: _fullDayEventBuilder, - scrollController: _scrollController, + scrollOffset: _lastScrollOffset, + scrollListener: _scrollPageListener, showHalfHours: widget.showHalfHours, showQuarterHours: widget.showQuarterHours, halfHourIndicatorSettings: @@ -895,6 +898,11 @@ class DayViewState extends State> { /// Returns the current visible date in day view. DateTime get currentDate => DateTime(_currentDate.year, _currentDate.month, _currentDate.day); + + /// Listener for every day page ScrollController + void _scrollPageListener(ScrollController controller) { + _lastScrollOffset = controller.offset; + } } class DayHeader {