关键代码
bottom: PreferredSize( preferredSize: Size.fromHeight(48), child: Material( //这里设置tab的背景色 color: Colors.green, child: TabBar( // indicator: ColorTabIndicator(Colors.black),//选中时标签颜色 indicatorColor: Colors.black,//选中时下划线颜色,如果使用了indicator这里设置无效 controller: _tabController, labelColor: Colors.white, unselectedLabelColor: Colors.yellow, tabs: _tabs.map((item)=>Tab(text: item,)).toList(), ), ), ) )
tabbar中的tab的背景颜色取的实际是AppBar的主题色,所以我们将tabbar放在Material中来重置了主题色,变成我们想要的背景色.
完整代码:
import 'package:flutter/material.dart'; class TabbarBgColorTest extends StatefulWidget{