首页 > 解决方案 > 页面中的颤振导航栏

问题描述

我在模态底部表的中间添加了一个导航栏。我希望它在您单击它们时显示不同的内容,例如位置或其他详细信息。这是它的外观截图:

https://gyazo.com/6b81b3b89ec19a0410bb5345dc2b511c

这是我正在关注的教程:

https://api.flutter.dev/flutter/material/BottomNavigationBar-class.html

在我的代码中,我可以只添加这部分代码:

  BottomNavigationBar(
    backgroundColor: Colors.deepPurple,
    selectedItemColor: Colors.grey,
    unselectedItemColor: Colors.white,
elevation: 0,
    items: const <BottomNavigationBarItem>[
      BottomNavigationBarItem(
        icon: Icon(Icons.home),
        label: 'Details',
      ),
      BottomNavigationBarItem(
        icon: Icon(Icons.business),
        label: 'Describtion',
      ),
      BottomNavigationBarItem(
        icon: Icon(Icons.school),
        label: 'Location',
      ),
    ],
    currentIndex: _selectedIndex,
    onTap: _onItemTapped,
  ),

我无法添加设置状态和内容,因为它给了我整个班级的错误。我应该添加什么才能更改您在导航栏下看到的文本?

标签: flutterflutter-dependencies

解决方案


为了能够像文档中那样使用底部栏,您应该使屏幕小部件有状态。阅读文档中的代码,您会看到脚手架是在有状态小部件的状态类中构建的。


推荐阅读