美文网首页
Flutter在iPhone X构建bottomNavigati

Flutter在iPhone X构建bottomNavigati

作者: 码农老王 | 来源:发表于2019-02-14 15:42 被阅读8次

使用 SafeArea widget来包裹tabbar的widget即可解决问题

问题如下


image.png

问题代码

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new DefaultTabController(
      length: 3,
      child: new Scaffold(
        body: new TabBarView(
          children: <Widget>[
            new FitstTabView(),
            new SecondTabView(),
            new ThirdTabView(),
          ],
        ),
        bottomNavigationBar: new TabBar(
            tabs: <Widget>[
              new Tab(icon: new Icon(Icons.directions_car)),
              new Tab(icon: new Icon(Icons.directions_transit)),
              new Tab(icon: new Icon(Icons.directions_bike)),
            ],
            labelColor: Colors.blue,
            unselectedLabelColor: Colors.white,
            indicatorColor: Colors.blue,
          ),
        backgroundColor: Colors.black,
      ),
    );
  }
}

解决的关键代码(使用 SafeArea widget来包裹)

bottomNavigationBar: SafeArea(
          child: new TabBar(
            tabs: <Widget>[
              new Tab(icon: new Icon(Icons.directions_car)),
              new Tab(icon: new Icon(Icons.directions_transit)),
              new Tab(icon: new Icon(Icons.directions_bike)),
            ],
            labelColor: Colors.blue,
            unselectedLabelColor: Colors.white,
            indicatorColor: Colors.blue,
          ),
        ),

其它相关资料参考
https://github.com/flutter/flutter/issues/12099
https://github.com/flutter/flutter/issues/12883
https://github.com/flutter/flutter/issues/12895

相关文章

网友评论

      本文标题:Flutter在iPhone X构建bottomNavigati

      本文链接:https://www.haomeiwen.com/subject/qjveeqtx.html