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.38k stars 378 forks source link

Is it possible to touch other views on top of the istview to swipe to close the panel when the listview scrolls up a certain distance? #329

Closed pengboboer closed 1 year ago

pengboboer commented 1 year ago

Describe the bug

When we use panelBuilder to build our view, we can get a ScrollController. Through this ScrollController, we can realize the linkage between the panel and the ListView. When the ListView slides to the top, and then slides down the panel, the panel will be closed. This is expected behavior

There is a view above the ListView, which we can think of as an appbar. When the ListView scrolls a certain distance, I hope that I can slide to close the panel when I touch and pull down the appbar

At present, there is no response to sliding this position. I know that this library may not support this function, but this interaction will greatly affect the user experience.

like this:

The listview has scrolled up a certain distance.

22

Expected behavior

When the ListView is scrolled to any position, not only in the initial state, I want that I can swipe down to close this panel by touching the appbar in the red area.

pengboboer commented 1 year ago

@akshathjain

pengboboer commented 1 year ago

I found the following code which manages the gesture slide:

 // handles the sliding gesture
  void _onGestureSlide(double dy) {
    // only slide the panel if scrolling is not enabled
    if (!_scrollingEnabled) {
      if (widget.slideDirection == SlideDirection.UP)
        _ac.value -= dy / (widget.maxHeight - widget.minHeight);
      else
        _ac.value += dy / (widget.maxHeight - widget.minHeight);
    }
    ......
  }

I write this part as a method, the name of the new method is: onChildWidgetPointerMove, and then provide it to the outside through PanelController.

Add this code in PanelController:

  void onChildWidgetPointerMove(PointerMoveEvent p) {
    _panelState!.onChildWidgetPointerMove(p);
  }

Wrapping around our Widget:

Listener(
    behavior: HitTestBehavior.opaque,
    onPointerMove: (p) => panelController.onChildWidgetPointerMove(p),
    child:XxxWidget()
)

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