Flutter Appbar操作

问题描述 投票:0回答:1

在android中,每个片段都有覆盖onCreateOptionsMenu,提供了在每个片段中添加单个选项菜单的可能性。当appbar与应用程序相同时,如何在从抽屉更改页面时进行颤动

android flutter
1个回答
2
投票

您可以在每个屏幕中添加AppBar。

 class SDF extends StatefulWidget {
  @override
  _SDFState createState() => _SDFState();
}

class _SDFState extends State<SDF> {
  int body = 0;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("I Am AppBar"),
        actions: getActions(body),
      ),
      body: getBody(body), //here you can add your body
      drawer: Drawer(
        child: Column(
          children: <Widget>[
             RaisedButton(
          onPressed: () {
            setState(() {
              body = 0; 
            });

          },
          child: Text("Home"),
        ),
        RaisedButton(
          onPressed: () {
            setState(() {
              body = 1;
            });

          },
          child: Text("Settings"),
        ),
          ],
        ),
      ),
    );
  }

  getBody(int body) {
    switch (body) {
      case 0:
        return Container(); // Home Screen

      case 1:
        return Container(); // Settings Screen
    }
  }

  getActions(int body) {
    switch (body) {
      case 0:
        return [
          Icon(Icons.settings),
          Icon(Icons.home),
        ]; // Home Screen

      case 1:
        return [
          Icon(Icons.home),
          Icon(Icons.settings),
        ]; // Settings Screen
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.