Repository navigation
TabBar throws assertion indicator != null || indicatorWeight > 0.0 despite a TabBarThemeData.indicator #188837
Description
Steps to Reproduce
When the tab indicator is supplied via TabBarThemeData.indicator (the idiomatic place for app-wide styling) and you set indicatorWeight: 0 on the TabBar widget to suppress the default underline weight, the constructor assertion throws — even though a valid indicator is present (from the theme).
The assertion in TabBar (packages/flutter/lib/src/material/tabs.dart, 3.44.4) is:
assert(indicator != null || (indicatorWeight > 0.0));It only inspects the widget-level indicator parameter and is blind to TabBarThemeData.indicator.
Minimal repro (flutter create, replace lib/main.dart, run):
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) => MaterialApp(
theme: ThemeData(
tabBarTheme: const TabBarThemeData(
indicator: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.all(Radius.circular(22)),
),
indicatorSize: TabBarIndicatorSize.tab,
),
),
home: DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
bottom: const TabBar(
indicatorWeight: 0, // <-- throws, despite the themed indicator above
tabs: [Tab(text: 'A'), Tab(text: 'B')],
),
),
body: const TabBarView(
children: [Center(child: Text('A')), Center(child: Text('B'))],
),
),
),
);
}Expected results
The TabBar builds. The themed indicator (red pill) is painted, and indicatorWeight: 0 is accepted because a valid indicator is provided by the theme — there is no default underline weight to add.
Actual results
Construction throws:
'package:flutter/src/material/tabs.dart': Failed assertion: line 1042 pos 16:
'indicator != null || (indicatorWeight > 0.0)': is not true.
The only workaround is to pass a non-zero epsilon weight (e.g. indicatorWeight: 0.0000001), because passing a widget-level indicator to satisfy the assert would override the themed indicator entirely (widget-level indicator takes precedence over TabBarThemeData.indicator), losing the app-wide styling. So there is no way to combine "indicator from theme" + "zero indicator weight" without a hack.
Notes / proposed fix
- This is distinct from TabBar indicatorWeight is not ignored as documented #171951 (closed as a documentation clarification via Update TabBar documentation to clarify indicatorWeight behavior #184104). That issue was about
indicatorWeightnot being ignored when a widget-level custom indicator is supplied. This report is about the assertion not recognizing a theme-level indicator, which is still present in 3.44.4. - The assertion is a construction-time check and therefore cannot see the resolved theme (no
BuildContextavailable in the constructor). A fix would be to either drop the assert, or move the validation to build time whereTabBarTheme.of(context).indicatoris known, so that a theme-supplied indicator satisfies the "indicator provided" condition.
Flutter Doctor
[✓] Flutter (Channel stable, 3.44.4, on Ubuntu 6.15.11-x64v3-xanmod1, locale en_DE.UTF-8)
• Framework revision ad70ec4617 (2026-06-24), engine a10d8ac38d
[✓] Android toolchain - develop for Android devices (Android SDK version 37.0.0)
[✓] Chrome - develop for the web
[✓] Connected device (3 available)
[✓] Network resources
• No issues found!
(Please paste your own flutter doctor -v when filing.)
Activity
suryaKommana2662 commentedon Jul 1, 2026
@qeepcologne Thanks for the detailed reproduction and the minimal sample. I was able to reproduce the issue on an Android emulator using the provided code. Routing this issue to
team-designfor further investigation. The following assertion is triggered:[-]TabBar assertion `indicator != null || indicatorWeight > 0.0` ignores `TabBarThemeData.indicator`, forcing an epsilon-weight hack[/-][+]TabBar throws assertion `indicator != null || indicatorWeight > 0.0` despite a `TabBarThemeData.indicator`[/+]dkwingsmt commentedon Jul 1, 2026
Thanks for the investigation. I think it makes sense to move this check to run-time.
Massinissa-Mouhoub commentedon Jul 8, 2026
@dkwingsmt the issue with the assertion being made at run-time is that it makes the error quite ugly on the screen, which I think is not good for developer experience.
This is what I got after moving the assertion from the constructors to inside
Decoration _getIndicator(TabBarIndicatorSize indicatorSize)method:test: add regression tests for TabBar indicatorWeight: 0 with themed …
test: add regression tests for TabBar indicatorWeight: 0 with themed …
[material_ui] Fix `TabBar` assertion to allow `indicatorWeight: 0` wi…