iOS设备中的Flutter TabBarView封面底部区域(滑块)

问题描述 投票:0回答:2

我在Flutter中相对较新,我这样编写简单的TabBarView。

class MyApp extends StatelessWidget {
  @override
   Widget build(BuildContext context) {
    return new MaterialApp(
       theme: ThemeData(
        primaryColor: HexColor("#2E58A1"),
      ), 
      home: DefaultTabController(
        length: 4,
        child: new Scaffold(
          body: TabBarView(
            physics: NeverScrollableScrollPhysics(),
            children: [
              new Page1(),
              new Page2(),
              new Page3(),
              new Container(
                color: Colors.red,
              ),
            ],
          ),
          bottomNavigationBar: new TabBar(
            tabs: [
              Tab(
                icon: new Icon(Icons.home),
              ),
              Tab(
                icon: new Icon(Icons.rss_feed),
              ),
              Tab(
                icon: new Icon(Icons.perm_identity),
              ),
              Tab(icon: new Icon(Icons.settings),)
            ],
            labelColor: HexColor("#2E58A1"),
            unselectedLabelColor: HexColor("#CBCCCD"),
            indicatorSize: TabBarIndicatorSize.label,
            indicatorPadding: EdgeInsets.all(5.0),
            indicatorColor: HexColor("#2E58A1"),
          ),
          backgroundColor: Colors.white,
        ),
      ),
    );
  }

在本机iOS应用程序中,它不会像这样重叠标签栏和滑块。

enter image description here

我应该如何重新编写代码?

ios flutter uitabbar
2个回答
0
投票

SafeArea小部件包裹MaterialApp

或者您可以只用SafeArea包裹您的TabBar

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: new MaterialApp(
        theme: ThemeData(),
        home: DefaultTabController(
          length: 4,
          child: new Scaffold(
            body: TabBarView(
              physics: NeverScrollableScrollPhysics(),
              children: [
              new Page1(),
              new Page2(),
              new Page3(),
                new Container(
                  color: Colors.red,
                ),
              ],
            ),
            bottomNavigationBar: new TabBar(
              tabs: [
                Tab(
                  icon: new Icon(Icons.home),
                ),
                Tab(
                  icon: new Icon(Icons.rss_feed),
                ),
                Tab(
                  icon: new Icon(Icons.perm_identity),
                ),
                Tab(
                  icon: new Icon(Icons.settings),
                )
              ],
            labelColor: HexColor("#2E58A1"),
            unselectedLabelColor: HexColor("#CBCCCD"),
              indicatorSize: TabBarIndicatorSize.label,
              indicatorPadding: EdgeInsets.all(5.0),
            indicatorColor: HexColor("#2E58A1"),
            ),
            backgroundColor: Colors.white,
          ),
        ),
      ),
    );
  }
} 

0
投票

将小部件包装到SafeArea中,它会添加足够的填充,以避免操作系统入侵

也建议设置

BottomNavigationBar(
...
elevation: 0,

根据此报告:https://github.com/flutter/flutter/issues/21688

© www.soinside.com 2019 - 2024. All rights reserved.