Flutter Drawer Widget - change Scaffold.body content

前端 未结 4 1477
死守一世寂寞
死守一世寂寞 2020-12-05 21:09

When using the Flutter Scaffold.Drawer - is it possible to have the links in the Drawer change the content (Scaffold.body) on the page?

Similarly to having links in

4条回答
  •  余生分开走
    2020-12-05 21:34

    That's a very good solution from Aziza! Thank you. It works! I'd just want to add that it can also work for the whole body by replacing it with a widget state:

    ...
    class _TestPageState extends State {
      String text = "Initial Text";
      Widget widgetForBody = SomeWidgetFromClass();
      ...
      ...
            children: [
              new Container(child: new DrawerHeader(child: new Container())),
              new Container (
                child: new Column(
                    children: [
                      new ListTile(leading: new Icon(Icons.info),
                          onTap:(){
                              setState((){
                                widgetForBody = AnotherWidgetFromClass();
                              });
                          }
                      ),
                      new ListTile(leading: new Icon(Icons.save),
                          onTap:(){
                            setState((){
                              widgetForBody = YetAnotherWidgetFromClass();
                            });
                          }
                      ),
    ...
    

提交回复
热议问题