Flutter Drawer Widget - change Scaffold.body content

前端 未结 4 1472
死守一世寂寞
死守一世寂寞 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:24

    Here is a easy and efficient way to do this with Full example

    class _MyPageState extends State {
      Widget bodyWidget;
    
      Widget drawer() {
        return
      }
    
      Widget bodyFirst() {
        return Container(
            color: Colors.green, child: Center(child: Text("First Page")));
      }
    
      Widget bodySecond() {
        return Container(
            color: Colors.limeAccent, child: Center(child: Text("Second Page")));
      }
    
      Widget bodyThird() {
        return Container(
            color: Colors.lightBlueAccent,
            child: Center(child: Text("Third Page")));
      }
      
      @override
      void initState() {
        super.initState();
        bodyWidget = bodyFirst();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          drawer: drawer(),
          appBar: AppBar(title: Text("My App")),
          body: bodyWidget,
        );
      }
    }
    

提交回复
热议问题