从Flutter的导航抽屉中删除应用栏标题?

时间:2019-01-09 10:39:03

标签: dart flutter navigation-drawer

我已经在Flutter中创建了一个导航抽屉。

此处提供来源-https://github.com/deadcoder0904/flutter_navigation_drawer

看起来像这样-

第一个屏幕

当我单击按钮时,它会转到

第二屏幕

当我单击按钮时,它会转到

标签屏幕

当我单击First Screen上的汉堡图标时,它会转到

抽屉屏幕

现在,当我在“抽屉”屏幕上单击“第二个列表项”时,我将得到第二个屏幕

相关代码在navigation_drawer.dart中,看起来像-

class NavigationDrawer extends StatefulWidget {
  _NavigationDrawerState createState() => _NavigationDrawerState();
}

class _NavigationDrawerState extends State<NavigationDrawer> {
  int _selectionIndex = 0;
  final drawerItems = [
    DrawerItem("First Screen", Icons.looks_one),
    DrawerItem("Second Screen", Icons.looks_two),
    DrawerItem("Tabs", Icons.tab),
  ];

  _getDrawerItemScreen(int pos) {
    switch (pos) {
      case 1:
        return SecondScreen();
      case 2:
        return Tabs();
      default:
        return FirstScreen();
    }
  }

  _onSelectItem(int index) {
    setState(() {
      _selectionIndex = index;
      _getDrawerItemScreen(_selectionIndex);
    });
    Navigator.of(context).pop();
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> drawerOptions = [];
    for (var i = 0; i < drawerItems.length; i++) {
      var d = drawerItems[i];
      drawerOptions.add(ListTile(
        leading: Icon(d.icon),
        title: Text(
          d.title,
          style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.w400),
        ),
        selected: i == _selectionIndex,
        onTap: () => _onSelectItem(i),
      ));
    }

    return Scaffold(
      appBar: AppBar(
        title: Text('First Screen'),
      ),
      drawer: Drawer(
        child: Column(
          children: <Widget>[
            UserAccountsDrawerHeader(
              accountName: Text('Akshay Kadam (A2K)'),
              accountEmail: Text('a2k@gmail.com'),
            ),
            Column(
              children: drawerOptions,
            ),
          ],
        ),
      ),
      body: _getDrawerItemScreen(_selectionIndex),
    );
  }
}

如何获得没有Hamburger IconFirst Screen标题的第二个屏幕?

1 个答案:

答案 0 :(得分:1)

首先,更改代码以设置主页

body: _getDrawerItemScreen(_selectionIndex),

body: FirstScreen(),

第二,

_onSelectItem(int index) {
    setState(() {
      _selectionIndex = index;
      _getDrawerItemScreen(_selectionIndex);
    });
    Navigator.pushReplacement(
      context,
      MaterialPageRoute(
        builder: (context) => _getDrawerItemScreen(_selectionIndex),
      ),
    );
  }