如果是监听index去设置背景颜色的话 ,会出现延时切换颜色的问题,可以做以下操作
TabBar(
isScrollable: true,
indicator: BoxDecoration(color: Colors.red,borderRadius: BorderRadius.circular(50)),//这个是可以设置颜色和圆角(指示器当背景用的意思)
labelColor: Colors.white,
labelStyle:
const TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
labelPadding:
const EdgeInsets.only(left: 8, right: 8),
unselectedLabelColor: const Color(0xFF1A1A1A),
unselectedLabelStyle:
const TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
controller: _tabController,
tabs: tabs.map((chose) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(
left: 15, right: 15, top: 9, bottom: 9),//这个是设置文字背景的长宽高
child: Text(chose.title),
)
],
);
}).toList())