Skyost / FlutterWeekView

Displays a highly customizable week view (or day view) which is able to display events, to be scrolled, to be zoomed-in & out and a lot more !
https://pub.dev/packages/flutter_week_view
MIT License
208 stars 89 forks source link

Be able to configure the initial scroll position of WeekView #38

Closed hnvn closed 4 years ago

hnvn commented 4 years ago

I need to launch WeekView and immediately jump to a selected event. Something may be initialDate and we can calculate scroll position out from it instead of only scrolling to current time.

@override
  void scrollToCurrentTime() {
    super.scrollToCurrentTime();

    int index = 0;
    if (widget.dateCount != null) {
      for (; index < widget.dateCount; index++) {
        if (Utils.sameDay(widget.dateCreator(index))) {
          break;
        }
      }
    }

    double topOffset = calculateTopOffset(HourMinute.now());
    double leftOffset = dayViewWidth * index;

    widget.controller.verticalScrollController.jumpTo(math.min<double>(topOffset, widget.controller.verticalScrollController.position.maxScrollExtent));
    widget.controller.horizontalScrollController.jumpTo(math.min<double>(leftOffset, widget.controller.horizontalScrollController.position.maxScrollExtent));
  }
hnvn commented 4 years ago

I create #41 to support this feature