Skip to content

Commit

Permalink
Synchronize InternalDayViewPage scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Luis authored and apurva010 committed May 8, 2024
1 parent cfd0612 commit 696afc9
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 42 deletions.
121 changes: 80 additions & 41 deletions lib/src/day_view/_internal_day_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import '../painters.dart';
import '../typedefs.dart';

/// Defines a single day page.
class InternalDayViewPage<T extends Object?> extends StatelessWidget {
class InternalDayViewPage<T extends Object?> extends StatefulWidget {
/// Width of the page
final double width;

Expand Down Expand Up @@ -116,7 +116,10 @@ class InternalDayViewPage<T extends Object?> 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;
Expand Down Expand Up @@ -151,7 +154,8 @@ class InternalDayViewPage<T extends Object?> 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,
Expand All @@ -163,34 +167,67 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
required this.onTileDoubleTap,
}) : super(key: key);

@override
State<InternalDayViewPage> createState() => _InternalDayViewPageState();
}

class _InternalDayViewPageState<T extends Object?>
extends State<InternalDayViewPage<T>> {
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,
Expand Down Expand Up @@ -241,48 +278,50 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
Align(
alignment: Alignment.centerRight,
child: EventGenerator<T>(
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,
),
Expand Down
10 changes: 9 additions & 1 deletion lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
late double _height;
late double _timeLineWidth;
late double _hourHeight;
late double _lastScrollOffset;
late DateTime _currentDate;
late DateTime _maxDate;
late DateTime _minDate;
Expand Down Expand Up @@ -349,6 +350,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
@override
void initState() {
super.initState();
_lastScrollOffset = widget.scrollOffset;

_reloadCallback = _reload;
_setDateRange();
Expand Down Expand Up @@ -484,7 +486,8 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
minuteSlotSize: widget.minuteSlotSize,
scrollNotifier: _scrollConfiguration,
fullDayEventBuilder: _fullDayEventBuilder,
scrollController: _scrollController,
scrollOffset: _lastScrollOffset,
scrollListener: _scrollPageListener,
showHalfHours: widget.showHalfHours,
showQuarterHours: widget.showQuarterHours,
halfHourIndicatorSettings:
Expand Down Expand Up @@ -895,6 +898,11 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
/// 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 {
Expand Down

0 comments on commit 696afc9

Please sign in to comment.