我正在使用底部导航栏和TabController.

推荐答案

我认为在你的情况下用PageView比用TabBarView要优雅得多.

enter image description here

class BottomBarExample extends StatefulWidget {
  @override
  _BottomBarExampleState createState() => new _BottomBarExampleState();
}

class _BottomBarExampleState extends State<BottomBarExample> {
  int _page = 0;
  PageController _c;
  @override
  void initState(){
    _c =  new PageController(
      initialPage: _page,
    );
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      bottomNavigationBar: new BottomNavigationBar(
        currentIndex: _page,
        onTap: (index){
          this._c.animateToPage(index,duration: const Duration(milliseconds: 500),curve: Curves.easeInOut);
        },
        items: <BottomNavigationBarItem>[
        new BottomNavigationBarItem(icon: new Icon(Icons.supervised_user_circle), title: new Text("Users")),
        new BottomNavigationBarItem(icon: new Icon(Icons.notifications), title: new Text("Alerts")),
        new BottomNavigationBarItem(icon: new Icon(Icons.email), title: new Text("Inbox")),

      ],

      ),
      body: new PageView(
        controller: _c,
        onPageChanged: (newPage){
          setState((){
            this._page=newPage;
          });
        },
        children: <Widget>[
          new Center(
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                new Icon(Icons.supervised_user_circle),
                new Text("Users")
              ],
            ),
          ),
          new Center(
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                new Icon(Icons.notifications),
                new Text("Alerts")
              ],
            ),
          ),
          new Center(
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                new Icon(Icons.mail),
                new Text("Inbox")
              ],
            ),
          ),
        ],
      ),
    );
  }
}

Dart相关问答推荐

如何找到这个Currate函数的返回类型?

自定义主题无法正常工作

Dart/Flutter ffi(外部函数接口)本机回调,例如:sqlite3_exec

PageView.builder 给出水平视口被给出无界高度错误

无法在 IOS 上使用 firebase 运行Flutter应用程序

如何从 Polymer Dart 触发自定义事件?

Bad state:在Flutter中从 addStream 添加项目时,您无法关闭主题

如何计算列表中元素的出现次数

如何垂直对齐行元素?

将Dart嵌入到应用程序中

设置Dart中非常量的默认值

如何在 flutter 中对json进行字符串化

Dart:异步抽象方法

如何在 Dart 中执行相当于 setTimeout + clearTimeout 的操作?

Dart MD5 字符串

你如何命名一个 Dart 类?

你如何在 Dart 中创建一个 Stream?

Dart 脚本会在浏览器中本地运行吗?

Dart 中不同的 Map 实现有什么区别?

在 Dart 中获取集合/列表中数字总和的最简洁方法是什么?