簡體   English   中英

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

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

我有一個 Sliver AppBar,它的背景顏色是透明的,滾動它會消失。 這里我想更改未選中標簽欄的顏色,雖然文本label顏色可以更改未選中標簽但是如何更改標簽rest的背景? 我已經嘗試過與此相關的先前已回答的查詢,但它對我不起作用,或者我可能遺漏了一些東西。 下面是帶有屏幕截圖的代碼。 非常感謝。 在此處輸入圖像描述

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

您可以對 colors 使用Ternary operator並將條件放在索引上,例如

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

並且 tab1 將引用索引 0 等等

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM