简体   繁体   中英

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. 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? 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

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

and tab1 would be refered to index 0 and so on

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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