Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronize InternalDayViewPage scroll #187

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 85 additions & 46 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 @@ -89,7 +89,10 @@ class InternalDayViewPage<T extends Object?> extends StatelessWidget {
/// Display full day events.
final FullDayEventBuilder<T> fullDayEventBuilder;

final ScrollController scrollController;
final void Function(ScrollController) scrollListener;

/// Scroll offset of day view page.
final double scrollOffset;

/// Defines a single day page.
const InternalDayViewPage({
Expand All @@ -116,78 +119,114 @@ 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,
}) : 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) {
return Container(
height: height,
width: width,
height: widget.height,
width: widget.width,
child: Column(
children: [
fullDayEventBuilder(controller.getFullDayEvent(date), date),
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,
),
),
PressDetector(
width: width,
height: height,
heightPerMinute: heightPerMinute,
date: date,
onDateTap: onDateTap,
onDateLongPress: onDateLongPress,
minuteSlotSize: minuteSlotSize,
width: widget.width,
height: widget.height,
heightPerMinute: widget.heightPerMinute,
date: widget.date,
onDateTap: widget.onDateTap,
onDateLongPress: widget.onDateLongPress,
minuteSlotSize: widget.minuteSlotSize,
),
Align(
alignment: Alignment.centerRight,
child: EventGenerator<T>(
height: height,
date: date,
onTileTap: onTileTap,
eventArranger: eventArranger,
events: controller.getEventsOnDay(date),
heightPerMinute: heightPerMinute,
eventTileBuilder: eventTileBuilder,
scrollNotifier: scrollNotifier,
width: width -
timeLineWidth -
hourIndicatorSettings.offset -
verticalLineOffset,
height: widget.height,
date: widget.date,
onTileTap: widget.onTileTap,
eventArranger: widget.eventArranger,
events: widget.controller.getEventsOnDay(widget.date),
heightPerMinute: widget.heightPerMinute,
eventTileBuilder: widget.eventTileBuilder,
scrollNotifier: widget.scrollNotifier,
width: widget.width -
widget.timeLineWidth -
widget.hourIndicatorSettings.offset -
widget.verticalLineOffset,
),
),
TimeLine(
height: height,
hourHeight: hourHeight,
timeLineBuilder: timeLineBuilder,
timeLineOffset: timeLineOffset,
timeLineWidth: timeLineWidth,
key: ValueKey(heightPerMinute),
height: widget.height,
hourHeight: widget.hourHeight,
timeLineBuilder: widget.timeLineBuilder,
timeLineOffset: widget.timeLineOffset,
timeLineWidth: widget.timeLineWidth,
key: ValueKey(widget.heightPerMinute),
),
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,
),
),
],
Expand Down
15 changes: 10 additions & 5 deletions lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,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 All @@ -241,15 +242,14 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {

EventController<T>? _controller;

late ScrollController _scrollController;

late VoidCallback _reloadCallback;

final _scrollConfiguration = EventScrollConfiguration<T>();

@override
void initState() {
super.initState();
_lastScrollOffset = widget.scrollOffset;

_reloadCallback = _reload;
_setDateRange();
Expand All @@ -259,8 +259,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
_regulateCurrentDate();

_calculateHeights();
_scrollController =
ScrollController(initialScrollOffset: widget.scrollOffset);

_pageController = PageController(initialPage: _currentIndex);
_eventArranger = widget.eventArranger ?? SideEventArranger<T>();
_assignBuilders();
Expand Down Expand Up @@ -381,7 +380,8 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
minuteSlotSize: widget.minuteSlotSize,
scrollNotifier: _scrollConfiguration,
fullDayEventBuilder: _fullDayEventBuilder,
scrollController: _scrollController,
scrollOffset: _lastScrollOffset,
scrollListener: _scrollPageListener,
),
);
},
Expand Down Expand Up @@ -677,4 +677,9 @@ 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;
}
}
Loading