Skip to content

TabBar throws assertion indicator != null || indicatorWeight > 0.0 despite a TabBarThemeData.indicator #188837

Closed
flutter/packages
#12696

Description

@qeepcologne

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 indicatorWeight not 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 BuildContext available in the constructor). A fix would be to either drop the assert, or move the validation to build time where TabBarTheme.of(context).indicator is 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

  1. suryaKommana2662 commented on Jul 1, 2026

    @suryaKommana2662

    @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-design for further investigation. The following assertion is triggered:

    'package:flutter/src/material/tabs.dart': Failed assertion:
    'indicator != null || (indicatorWeight > 0.0)': is not true.
  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on Jul 1, 2026
  3. changed the title [-]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`[/+] on Jul 1, 2026
  4. added
    P2Important issues not at the top of the work list
    triaged-designTriaged by Design Languages team
    on Jul 1, 2026
  5. dkwingsmt commented on Jul 1, 2026

    @dkwingsmt
    Contributor

    Thanks for the investigation. I think it makes sense to move this check to run-time.

  6. Massinissa-Mouhoub commented on Jul 8, 2026

    @Massinissa-Mouhoub

    @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.

    Image

    This is what I got after moving the assertion from the constructors to inside Decoration _getIndicator(TabBarIndicatorSize indicatorSize) method:

    Decoration _getIndicator(TabBarIndicatorSize indicatorSize) {
      final ThemeData theme = Theme.of(context);
      final TabBarThemeData tabBarTheme = TabBarTheme.of(context);
    
      if (widget.indicator != null) {
        return widget.indicator!;
      }
      if (tabBarTheme.indicator != null) {
        return tabBarTheme.indicator!;
      }
      assert(
        widget.indicatorWeight > 0.0,
        'The indicatorWeight must be greater than 0 when the TabBar '
        'draws its default underline indicator (i.e. when no indicator is '
        'provided by the TabBar or the TabBarTheme).',
      );
        
      // Rest of the method
    }
  7. added
    packageflutter/packages repository. See also p: labels.
    and removed
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listhas reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions