如何在颤抖的“ TabBar”中更改未选中的标签背景颜色?

时间:2019-11-26 08:12:47

标签: flutter flutter-layout

喜欢我的代码:

TabBar(
                  // isScrollable: true,
                  unselectedLabelColor: Colors.grey,

                  labelColor: Colors.black,
                  // labelColor: Colors.white,
                  // indicatorSize: TabBarIndicatorSize.tab,
                  indicator: BoxDecoration(
                      borderRadius: BorderRadius.circular(50),
                      color: Colors.white),
                  tabs: tabs,
                  controller: _tabController,
                )

我正在尝试更改未选中标签的背景颜色,例如在我的模拟中 tabs

1 个答案:

答案 0 :(得分:0)

 TabController _tabController;

 @override
 void initState() {
   super.initState();
  _tabController = new TabController(vsync: this, length: 2);
  _tabController.addListener(_handleTabSelection);
 }

 void _handleTabSelection() {
    setState(() {
     });
 }

 TabBar(
        controller: _tabController,
        indicatorColor: Colors.grey,
        labelColor: Colors.black,
        unselectedLabelColor: Colors.grey,
        tabs: [
          Tab(
              text: 'First',
              icon: Icon(Icons.home,
                  color: _tabController.index == 0
                      ? Colors.black
                      : Colors.grey)),
          Tab(
              text: 'Second',
              icon: Icon(Icons.person,
                  color: _tabController.index == 1
                      ? Colors.black
                      : Colors.grey)),
  )