I’ve been using this custom container to create the tab for the TabBar. I’d like the selected tab to display a different color than the unselected tabs. The ‘2nd’ tab is an example of how the selected tab should be, but i’ve hard coded it to show as example.
TabBar(
padding: EdgeInsets.zero,
labelPadding: EdgeInsets.zero,
indicatorPadding: EdgeInsets.zero,
tabs: [
Container(
height: 50,
width: 120,
decoration: BoxDecoration(
color: const Color(0xFFF4F1F1),
border: Border.all(color: const Color(0xFFFAC5C5), width: 2),
borderRadius: const BorderRadius.all(Radius.circular(25)),
),
child: OutlinedButton(
onPressed: () {},
child: const Text('1st'),
),
),
Container(
height: 50,
width: 120,
decoration: BoxDecoration(
color: const Color(0xfffacdc9),
border: Border.all(color: const Color(0xFFFAC5C5), width: 2),
borderRadius: const BorderRadius.all(Radius.circular(25)),
),
child: OutlinedButton(
onPressed: () {},
child: const Text('2nd'),
),
),
Container(
height: 50,
width: 120,
decoration: BoxDecoration(
color: const Color(0xFFF4F1F1),
border: Border.all(color: const Color(0xfffccccc), width: 2),
borderRadius: const BorderRadius.all(Radius.circular(25)),
),
child: OutlinedButton(
onPressed: () {},
child: const Text('3rd'),
),
),
],
),
),
I have tried to improvise using some indicator properties of Tabbar, but didn’t work because it only shows as a shadow for the container instead of being the foreground color.
TabBar(indicator:
BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(15)),'''
2
Answers
try the following
use Tabbar with tab as children
additional the tabs can be customized to suit your design
You need to use
TabController
for catchingTabBar
‘s current index, and changing that index.