简体   繁体   English

如何更改Flutter中未选中的Tab Bar背景?

[英]How to change the background of unselected Tab Bar in Flutter?

I have a Sliver AppBar and its background color is transparent and on scrolling it disappears.我有一个 Sliver AppBar,它的背景颜色是透明的,滚动它会消失。 Here I want to change the color of unselected tab bar, though the text label color can be changed of unselected tab but how to change the background of rest of the tabs?这里我想更改未选中标签栏的颜色,虽然文本label颜色可以更改未选中标签但是如何更改标签rest的背景? I have tried the previous answered queries related to this but it is not working for me or may be I am missing something.我已经尝试过与此相关的先前已回答的查询,但它对我不起作用,或者我可能遗漏了一些东西。 Here is the code below with screen shot.下面是带有屏幕截图的代码。 Thanks much.非常感谢。 在此处输入图像描述

 NestedScrollView(
              controller: _scrollViewController,
              headerSliverBuilder: (BuildContext context, bool boxIsScrolled){
                return <Widget>[
                  SliverAppBar(
                    automaticallyImplyLeading: false,
                    backgroundColor: Colors.transparent,
                    floating: true,
                    pinned: false,
                    snap: true,
                    title: TabBar(

                        isScrollable: true,
                        controller: _tabController,
                        unselectedLabelColor: mRed,
                        labelColor: white,
                        indicatorColor: Colors.blueGrey,
                        indicatorSize: TabBarIndicatorSize.label,
                        indicator: BoxDecoration(
                            borderRadius: BorderRadius.circular(50),
                            color: mRed),
                        tabs: [
                          Tab(
                            child: Container(
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(50),
                                  border:  
                                  Border.all( color:mRed , width: 1),
                              ),
                              padding: EdgeInsets.all(15),
                              child: Align(
                                alignment: Alignment.center,
                                child: Text("APPS",),
                              ),
                            ),
                          ),

you can use Ternary operator for colors and put condition on index like您可以对 colors 使用Ternary operator并将条件放在索引上,例如

Index == 0 ? Colors.black : Colors.white,

and tab1 would be refered to index 0 and so on并且 tab1 将引用索引 0 等等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM