flutter_calendar_view icon indicating copy to clipboard operation
flutter_calendar_view copied to clipboard

Synchronize scroll between pages [DayView, WeekView]

Open Freyien opened this issue 2 years ago • 0 comments

Version: calendar_view: ^1.0.2

Widgets: DayView and WeekView

Behavior: Scroll restart when I change page in PageView. If I use the scrollOffset property when changing pages there is an animation that affects the UX.

Wish: I would like that when changing the page (day, week) the scroll would be maintained, as it happens in Google calendar. Only use scrollOffset for first position, after synchronize position.

Code for reply WeekView behavior

class WeeklyCalendar extends StatelessWidget {
  const WeeklyCalendar();

  double _calculateScrollOffset() {
    final hourHeight = 1.5 * 60;
    final height = hourHeight * (_now.hour - 1);
    return height;
  }

  @override
  Widget build(BuildContext context) {
    final gKey = GlobalKey<WeekViewState>();
    final scrollOffset = _calculateScrollOffset();

    return WeekView(
      key: gKey,
      showLiveTimeLineInAllDays: true,
      minDay: _now.subtract(Duration(days: 60)),
      maxDay: _now.add(Duration(days: 60)),
      initialDay: _now,
      scrollOffset: scrollOffset,
    );
  }
}

https://user-images.githubusercontent.com/18446487/218242101-a678113e-8202-4c3c-876c-3a57a3e4a0c1.mov

Freyien avatar Feb 11 '23 05:02 Freyien