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

Can you add an optional parameter as position to PanelState.OPEN, or add another state PanelState.PARTIALLY_OPEN({int position})? #226

Open sdas19 opened 3 years ago

sdas19 commented 3 years ago

The requirement is user should be able to see sliding_panel opened by default, not to maxHeight but to a specific position. However, later on, the user can drag the panel within maxHeight and minHeight.

Tried several ways to accomplish this,

  1. Initially kept defaultPanelState as CLOSED and tried overriding onPanelClosed to change the panel position by the controller with one time check, however onPanelClosed callback only triggers when the user interacts with the panel for the first time.
  2. Used setState for this widget to increase the maxHeight as soon as it is rendered. This solves the issue but the max height change transition experienced by the user is not smooth, it jumps to the maxHeight.

Even if there is any other clean way already available to achieve it, please share that as well.

arafaysaleem commented 3 years ago

You can use animatePanelToPosition method available on the panel controller.

animatePanelToPosition(double value, {Duration duration, Curve curve = Curves.linear})

Attach this to to a postframe callback so it gets called after the UI is built.

late final panelController;

void initState() {
    super.initState();
    panelController = PanelController();
    WidgetsBinding.instance.addPostFrameCallback((_) => 
       panelController.animatePanelToPosition(yourPosition, duration: Duration(milliseconds: 0))
    );
}