颤振标签未正确加下划线

时间:2019-09-04 18:56:35

标签: flutter

我有以下标签:

class _HomeState extends State<Home> {

  int _currentIndex = 0;

  final List<Widget> _children = [
    DefaultTabController(
        length: 3,
        child: Scaffold(
            appBar: AppBar(
              flexibleSpace: SafeArea(
                child: TabBar(
                  tabs: [
                    Tab(icon: Icon(FontAwesomeIcons.listAlt)),
                    Tab(icon: Icon(FontAwesomeIcons.map)),
                    Tab(icon: Icon(FontAwesomeIcons.cog))
                  ],
                )
              )
            ),
            body: TabBarView(
              children: [
                TrendingList(),
                TrendingMap(),
                TrendingConfiguration()
              ],
            )
        )
    ),
    PlaceholderWidget(Colors.white),
    PlaceholderWidget(Colors.deepOrange),
    PlaceholderWidget(Colors.green)
  ];

  void onTabTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _children[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        onTap: onTabTapped,
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        items: [
          BottomNavigationBarItem(
            icon: new Icon(FontAwesomeIcons.chartLine),
            title: new Text('Trending'),
          ),
          BottomNavigationBarItem(
            icon: new Icon(FontAwesomeIcons.glasses),
            title: new Text('Watchlist'),
          ),
          BottomNavigationBarItem(
              icon: Icon(FontAwesomeIcons.user),
              title: Text('Me'),
          ),
          BottomNavigationBarItem(
            icon: Icon(FontAwesomeIcons.bell),
            title: Text('Notifications'),
          )
        ],
      ),
    );
  }
}

结果如下:

enter image description here

为什么我的标签页未正确加下划线,该如何解决?
我不要头衔

1 个答案:

答案 0 :(得分:0)

使用TabBar的正确位置是bottom中的AppBar

如文档中所述-https://api.flutter.dev/flutter/material/AppBar-class.html

  

底部通常用于TabBar。

代码:

child: Scaffold(
            appBar: AppBar(
              title: Text('Dummy'),
              bottom: TabBar(
                tabs: [
                  Tab(icon: Icon(FontAwesomeIcons.listAlt)),
                  Tab(icon: Icon(FontAwesomeIcons.map)),
                  Tab(icon: Icon(FontAwesomeIcons.cog))
                ],
              ),
            ),

enter image description here

更新:

代码:无标题。

appBar: AppBar(
              flexibleSpace: SafeArea(
                child: SizedBox(
                  height: kToolbarHeight,
                  child: TabBar(
                    tabs: [
                      Tab(icon: Icon(FontAwesomeIcons.listAlt)),
                      Tab(icon: Icon(FontAwesomeIcons.map)),
                      Tab(icon: Icon(FontAwesomeIcons.cog))
                    ],
                  ),
                ),
              ),
              bottom: PreferredSize(child: SizedBox(), preferredSize: Size.zero),
            ),

enter image description here