提问者:小点点

在flutter中从底部导航栏开始的页面之间的路由


我有4页在flutter项目,我想:

1-当用户按下手机的后退按钮时,显示底部导航栏页面与主页之间的路由。

2-当用户未使用bottomnavigationbar进入页面时,bottomnavigationbar中该页面的图标将与该页面同步。

null


共1个答案

匿名用户

您可以在scaffold内的bottomnavigationbar属性内提供两个内容:

第一个是bottomnavigationbar,第二个是tabbar

>

  • 使用bottomnavigationbar

    var _currentIndex = 0;
    var _pages = [
      HomePage(),
      Page2(),
      Page3()
      Page4()
    ];
    
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text('Bottom Navigation Bar'),
        ),
        body: _pages[_currentIndex],
        bottomNavigationBar: BottomNavigationBar(
          onTap: (int index) {
            setState(() {
              _currentIndex = index;
            });
          },
          currentIndex: _currentIndex,
          items: [
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              title: Text('Home'),
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.message),
              title: Text('Page2'),
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.person),
              title: Text('Page3')
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.photo),
              title: Text('Page4')
            ),
          ],
        ),
      );
    }
    

    null