如何在Flutter中改变指示器颜色

xurqigkl  于 2023-01-02  发布在  Flutter
关注(0)|答案(2)|浏览(223)

如下图所示,我有第一个标签颜色为绿色
选项卡标题是彩色的,下划线不是

是否可以将标题下的行着色为相同的颜色green

child: TabBar(
                  onTap: (index) {
                    setState(() {
                      selectedIndex = index;
                    });
                  },
                  isScrollable: false,
                  padding: const EdgeInsets.symmetric(horizontal: 10),
                  controller: _tabController,
                  labelColor: getIndicatorAndLabelColor(selectedIndex),
                  unselectedLabelColor: Colors.black,
                  indicatorWeight: 4,
                  indicatorColor: getIndicatorAndLabelColor(selectedIndex),
                 indicatorPadding:
                      const EdgeInsets.only(left: 15, right: 15, bottom: 10),
                  indicator: const ShapeDecoration(
                      shape: UnderlineInputBorder(
                          borderSide: BorderSide(
                              color: myAccentColor,
                              width: 3,
                              style: BorderStyle.solid))),
                  tabs: const [
                    Tab(
                      text: 'APPROVED',
                    ),
                    Tab(
                      text: 'DENIED',
                    ),
                    Tab(
                      text: 'PENDING',
                    ),
                  ],
                ),
krcsximq

krcsximq1#

您可以使用indicatorColor将其设置为绿色。

TabBar(
  indicatorColor: Colors.green, //this one , you can remove `getIndicatorAndLabelColor`
  indicatorWeight: 4,
  indicatorPadding:
      const EdgeInsets.only(left: 15, right: 15, bottom: 10),
  tabs: <Widget>[
50pmv0ei

50pmv0ei2#

谢谢@Yeasin Sheikh,我终于找到了解决办法

indicator: ShapeDecoration(
              shape: UnderlineInputBorder(
                borderSide: BorderSide(
                    color: Colors.green,
                    width: 3,
                    style: BorderStyle.solid),
              ),
            ),

相关问题