BottomNavigationBar + BottomNavigationBarItem导航的另外一种用法

Posted xiongwei

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BottomNavigationBar + BottomNavigationBarItem导航的另外一种用法相关的知识,希望对你有一定的参考价值。

import package:flutter/material.dart;
import News.dart;
import Video.dart;
import Chat.dart;
import MyId.dart;

class AppTwo extends StatelessWidget {
  @override
  Widget build(BuildContext context) => MaterialApp(home: Home());
}

class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  int _currentIndex = 0;
  final List<Widget> _children = [
    NewsPage(),
    VideoPage(),
    ChatPage(),
    MyIdPage()
  ];

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
//      appBar: AppBar(
//        title: Text("第二种方式"),
//        centerTitle: true,
//      ),
      body: _children[_currentIndex],
//      CupertinoTabBar 是ios分格
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: onTabTapped,
        items: [
          BottomNavigationBarItem(
              title: new Text("Home"), icon: new Icon(Icons.home)),
          BottomNavigationBarItem(
              title: new Text("List"), icon: new Icon(Icons.list)),
          BottomNavigationBarItem(
              title: new Text("Message"), icon: new Icon(Icons.message)),
        ],
      ),
    );

  }

  void onTabTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }
}
import package:flutter/material.dart;
import Guide.dart;

void main() => runApp(new AppTwo());

 

以上是关于BottomNavigationBar + BottomNavigationBarItem导航的另外一种用法的主要内容,如果未能解决你的问题,请参考以下文章

Android BottomNavigationBar导航栏

使用 Flutter 导航和路由时如何保持 BottomNavigationBar

Flutter -------- BottomNavigationBar 界面切换

BottomNavigationBar-更改标签图标颜色

如何在 BLOC 的 Flutter 中的 BottomNavigationBar 中设置 currentIndex?

滚动时如何隐藏 BottomNavigationBar - Flutter