How to set an initialOffset to linked ScrollControllers (aka LinkedScrollControllerGroup)

288 views Asked by At

I'm using this great package https://pub.dev/packages/linked_scroll_controller , and following this amazing tutorial on how to set up bidirectional scrolling table : https://crizantlai.medium.com/flutter-creating-a-two-direction-scrolling-table-with-fixed-head-and-column-4a34fc01378f .

Everything works great, however i cannot set an initialOffset to the linked ScrollControllers (like one would do with a simple ScrollController) without modifying the package. There must be something i missed or did not understand.

Here is my modification that works:

  ScrollController addAndGet(double initialOffset) {      //<---- add initialOffset here
    final initialScrollOffset = _attachedControllers.isEmpty
        ? initialOffset                                   //<---- add initialOffset here
        : _attachedControllers.first.position.pixels;
    final controller =
        _LinkedScrollController(this, initialScrollOffset: initialScrollOffset);
    _allControllers.add(controller);
    controller.addListener(_offsetNotifier.notifyListeners);
    return controller;
  }

.. and (for the exemple that i linked) modify the 2 initState methods :

  void initState() {
    super.initState();
    _controllers = LinkedScrollControllerGroup();
    _headController = _controllers.addAndGet(yourOffset);
    _bodyController = _controllers.addAndGet(yourOffset);
  }

If anyone has an idea how to implement this without this modification ?

0

There are 0 answers