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

Changing panelBody at runtime #125

Closed ArefMozafari closed 4 years ago

ArefMozafari commented 4 years ago

Hi there how can i change the panelBody at the run time? because i'm using the panel for my root widget and for each item that user selected in current screen i need to show different body in the panel

akshathjain commented 4 years ago

I'd recommend maintaining an enum that describes all the states of your panel. When the state is supposed to change, call setState() and update an enum variable. For example:

enum PanelWidgetState{
    WIDGET_ONE,
    WIDGET_TWO
}

PanelWidgetState _pws;

Widget build(BuildContext context){
    return SlidingUpPanel(
        panel: _panel(),
        ...
    );
}

// called whenever the UI is supposed to change
void _onChange(){
    setState((){
        if(some_condition) _pws = PanelWidgetState.WIDGET_ONE;
        ...
    });
}

Widget _panel(){
    if (_pws == PanelWidgetState.WIDGET_ONE) return WidgetOne();
    else if ...
}
ArefMozafari commented 4 years ago

Thank you