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

Viewed 1125

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. enter image description here

 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",),
                              ),
                            ),
                          ),
1 Answers

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

Related