How to use BottomNavigationBar with Navigator?

后端 未结 6 779
北荒
北荒 2020-12-02 08:36

The Flutter Gallery example of BottomNavigationBar uses a Stack of FadeTransitions in the body of the Scaffold.

I

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 09:03

    Output:

    Code:

    int _index = 0;
    
    @override
    Widget build(BuildContext context) {
      Widget child;
      switch (_index) {
        case 0:
          child = FlutterLogo();
          break;
        case 1:
          child = FlutterLogo(colors: Colors.orange);
          break;
        case 2:
          child = FlutterLogo(colors: Colors.red);
          break;
      }
    
      return Scaffold(
        body: SizedBox.expand(child: child),
        bottomNavigationBar: BottomNavigationBar(
          onTap: (newIndex) => setState(() => _index = newIndex),
          currentIndex: _index,
          items: [
            BottomNavigationBarItem(icon: Icon(Icons.looks_one), title: Text("Blue")),
            BottomNavigationBarItem(icon: Icon(Icons.looks_two), title: Text("Orange")),
            BottomNavigationBarItem(icon: Icon(Icons.looks_3), title: Text("Red")),
          ],
        ),
      );
    }
    

提交回复
热议问题