I created a custom indicator for tab bar using Decorator. I want to create a unselected indicator for not selected tabs in tab bar.
I did a container with custom decoration but current selected indicator draws behind container decoration.
new TabBar(
labelColor: Colors.black,
unselectedLabelColor: Colors.grey,
indicator: new CustomTabIndicator(),
tabs: [
new Container(decoration: new CustomTabInactive(),child: Tab(icon: Icon(Icons.person )))])
Instead of using container in tabs, try this (wrapping the TabBar with container and providing bottom border
Container(
//This is responsible for the background of the tabbar, does the magic
decoration: BoxDecoration(
//This is for background color
color: Colors.white.withOpacity(0.0),
//This is for bottom border that is needed
border: Border(bottom: BorderSide(color: Colors.grey, width: 0.8))),
child: TabBar(
controller: _controller,
tabs: [
...
]
)
Will not look exactly as you want, but will give underlined indication to unselected tabs.
You can use Stack/Container and TabBar together to make the underline
Stack(
fit: StackFit.passthrough,
alignment: Alignment.bottomCenter,
children: <Widget>[
Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: colorSecondary, width: 2.0),
),
),
),
TabBar(
isScrollable: true,
onTap: (index) => tabsModel.value = listTabsModel[index],
tabs: listTabsModel
.map(
(value) => Tab(
child: value.tabComponent,
),
)
.toList(),
),
],
);
TabBar with an underline for unselected
Not exactly what you are looking for but it can give the underline for un-selected tab.
I think you can use below code with plugin.
TabBar(
controller: tabController,
tabs: [
Tab(text: "ADCD"),
Tab(text: "EFGH"),
Tab(text: "IJKL"),
Tab(text: "MNOP"),
Tab(text: "QRST"),
],
labelColor: Colors.white,
labelStyle: TextStyle(
fontSize: 12.0, fontWeight: FontWeight.w700, fontFamily: 'helvetica'),
unselectedLabelColor: Colors.black,
unselectedLabelStyle: TextStyle(
fontSize: 12.0, fontWeight: FontWeight.w400, fontFamily: 'helvetica'),
isScrollable: true,
indicator: new BubbleTabIndicator(
indicatorHeight: p_35,
indicatorColor: const Color(0xFF58c8e3),
tabBarIndicatorSize: TabBarIndicatorSize.tab,
),
);
I have use this plugin for "BubbleTabIndicator" https://pub.dev/packages/bubble_tab_indicator
来源:https://stackoverflow.com/questions/52028730/how-to-create-unselected-indicator-for-tab-bar-in-flutter