I try to make TabBar with indicator but the tab item not filling the remaining space so the indicator just wrap the text. I want to set the indicator to fill the remaining space.
Here is my code
Container(
height: 45,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(
8,
),
),
child: TabBar(
indicator: BoxDecoration(
borderRadius: BorderRadius.circular(
8,
),
color: Colors.lightBlueAccent,
),
dividerColor: Colors.transparent,
tabAlignment: TabAlignment.fill,
labelColor: Colors.white,
unselectedLabelColor: Colors.white,
controller: tabController,
tabs: const [
Expanded(
child: Tab(
text: 'Upload Video Url',
),
),
Expanded(
child: Tab(
text: 'Upload File',
),
),
],
),
)
The result look like this
I try to make the tabbar from Flutter – How to make a custom TabBar but still can’t fill remaining space.
I also try to use Expanded on Tab but still not change.
TabBar(
indicator: BoxDecoration(
borderRadius: BorderRadius.circular(
8,
),
color: Colors.lightBlueAccent,
),
dividerColor: Colors.transparent,
tabAlignment: TabAlignment.fill,
labelColor: Colors.white,
unselectedLabelColor: Colors.white,
controller: tabController,
tabs: const [
Expanded(
child: Tab(
text: 'Upload Video Url',
),
),
Expanded(
child: Tab(
text: 'Upload File',
),
),
],
)
3
Answers
Instead of
Tab
you can UseContainer
with custom config, also you need to setlabelPadding
to zero like this:Use indicatorSize: TabBarIndicatorSize.tab, default property that is fulfill your remaining space
add this property indicatorSize: TabBarIndicatorSize.tab, and remove Expanded Widget