How to add underline to unselected tabs, like this:
https://ibb.co/mfkzKp
Here you can see it is gray colour for unselected tabs, and blue for selected.
To create a tab in it, create a tab list and create an object of its TabController. TabController _tabController; Initalize the TabController inside the initState() method and also override it in the dispose() method. The CustomTabBar results can be seen in the image.
I haven't found any reference in the documentation about how to customize disabled indicator. However, you can build your own widget that will take additional decoration parameter:
class DecoratedTabBar extends StatelessWidget implements PreferredSizeWidget {
DecoratedTabBar({@required this.tabBar, @required this.decoration});
final TabBar tabBar;
final BoxDecoration decoration;
@override
Size get preferredSize => tabBar.preferredSize;
@override
Widget build(BuildContext context) {
return Stack(
children: [
Positioned.fill(child: Container(decoration: decoration)),
tabBar,
],
);
}
}
Then you can decorate your TabBar however you want:
appBar: AppBar(
bottom: DecoratedTabBar(
tabBar: TabBar(
tabs: [
// ...
],
),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.blue,
width: 2.0,
),
),
),
),
),
Which will result in desired behavior:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With