akshathjain / sliding_up_panel

A draggable Flutter widget that makes implementing a SlidingUpPanel much easier!
https://pub.dartlang.org/packages/sliding_up_panel
Other
1.36k stars 377 forks source link

When the Listview position is at 0, calling the jumpTo or animateTo methods of ScrollController is invalid. #330

Closed pengboboer closed 1 year ago

pengboboer commented 1 year ago

Describe the bug

Using PanelBuilder to build the panel, I obtained the ScrollController and passed it into the Listview. However, when I called the jumpTo and animateTo methods of the ScrollController, there was no effect.

I have a comment page where I want the keyboard to pop up and the Listview to scroll to the position of a certain item when I click on it. However, when I call the jumpTo or animateTo methods at the initial position, it doesn't work. jumpTo and animateTo only take effect when manually scrolling the Listview so that it is not in the 0 position.

like this

I called the animateTo method when bouncing the keyboard, but it had no effect.

3333

Expected behavior

Whether the Listview is in its initial position or scrolling for a certain distance, I can make it scroll correctly by calling the jumpTo or animateTo methods of ScrollController.

pengboboer commented 1 year ago

I found the cause of the problem:

// prevent the panel content from being scrolled only if the widget is
    // draggable and panel scrolling is enabled
    _sc = new ScrollController();
    _sc.addListener(() {
      if (widget.isDraggable && !_scrollingEnabled) _sc.jumpTo(0);
    });

Because the initial value of _scrollingEnabled is false.

When I call the scroll method, this method will eventually be called: _sc.jumpTo(0).

I think I should change the value of _scrollingEnabled at this moment.

Add this code in PanelController:

  void setScrollEnable(bool enable) {
    _panelState!.scrollingEnabled = enable;
  }

This method is called before the list is scrolled.

Like this:

panelController.setScrollEnable(true);
scrollController.jumpTo(xxx);
// scrollController. animateTo(xxx);

This solved my problem and it works fine

pengboboer commented 1 year ago

This is my demo, if you need it, I hope it can help you.

https://github.com/pengboboer/flutter_comment_panel_example