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 379 forks source link

SlidingUpPanelController.close() needs to jump the panel ScrollController to 0, or make it an option #282

Open Sam-Guru-In-Training opened 2 years ago

Sam-Guru-In-Training commented 2 years ago

Describe the bug My panel has a ListView, with a ScrollController attached. If I use the ScrollController passed through from panelBuilder like: panelBuilder: (slideUpPanelScrollController) =>

Then scrolling will function correctly, I can scroll the ListView to the top, then the panel will begin scrolling down revealing the background.

However I need to switch the panel content when the user selects items from the appDrawer.

When the user selects a new item from the AppDrawer I need to ensure the panel's refreshed ListView starts at .jumpTo(0), the top.

So I use a global ScrollController to control the panel's Listview.

This solves the problem when offering a peek at the ListView - having it a fifth opened on an AppDrawer menu item select, but creates a bug when closing. The ListView scrolls up as the Panel draws down. Not what the user expects, and a lousy experience.

If I do it as per the instruction, well when you force close the panel, using slidingPanelController.close(), well it doesn't automatically jump the panel's ListView controller to the top. So if I open a content refreshed panel, it can open midway down.

It would be great if slidingPanelController.close() also jumped the panel's ScrollController to the top, or if there was a recommended way to deal with this scenario.

AErmek commented 2 years ago

@Sam-Guru-In-Training hi, did you solve this issue?

Sam-Guru-In-Training commented 2 years ago

I found a way to make it work, with some kind kind guidance. But still, it would be cool to have it as a bool to keep the code cleaner and more easily readable. A 'resetScrollPositionOnPanelClosed' boolean property.

AErmek commented 2 years ago

@Sam-Guru-In-Training after some researches i found Pull request where exactly this issue was fixed, here: https://github.com/willbryant/sliding_up_panel/tree/master and just changed in pubspec.yaml to this repo

thorizer commented 1 year ago

@Sam-Guru-In-Training what was the way?

Sam-Guru-In-Training commented 1 year ago

I had a great deal of help from Stackoverflow to solve it.

The answer is here

The SlidingUpPanel Widget panelBuild method requires a ScrollController. I had to copy this to _scrollController, so I can use it outside Panel's build in the pages build() method.

        panelBuilder: (ScrollController sc) {
          // ! So we can use local scrollcontroller outside the panel builder
          _scrollController ??= sc;
          return ScrollingList(
            scrollController: _scrollController!,
          );

2 further functions were create to administer _scrollController's state from the App's build() method.

These were called from the app Drawer I think, to close the SlidingUpPanel. And also from interaction with a close panel widget, at the top of the SlidingUp Panel.