diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index 2bb5f44971..79e9954051 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -1220,10 +1220,7 @@ class _TabBarState extends State { return tabBarTheme.indicator!; } - Color color = widget.indicatorColor - ?? (theme.useMaterial3 - ? tabBarTheme.indicatorColor ?? _defaults.indicatorColor! - : Theme.of(context).indicatorColor); + Color color = widget.indicatorColor ?? tabBarTheme.indicatorColor ?? _defaults.indicatorColor!; // ThemeData tries to avoid this by having indicatorColor avoid being the // primaryColor. However, it's possible that the tab bar is on a // Material that isn't the primaryColor. In that case, if the indicator diff --git a/packages/flutter/test/material/tab_bar_theme_test.dart b/packages/flutter/test/material/tab_bar_theme_test.dart index 4a6f518b6b..e137c541ad 100644 --- a/packages/flutter/test/material/tab_bar_theme_test.dart +++ b/packages/flutter/test/material/tab_bar_theme_test.dart @@ -1132,4 +1132,90 @@ void main() { expect(tabTwoRect.right, equals(tabTwoRight)); }); }); + + testWidgets('Material3 - TabBar indicator respects TabBarTheme.indicatorColor', (WidgetTester tester) async { + final List tabs = List.generate(4, (int index) { + return Tab(text: 'Tab $index'); + }); + + final TabController controller = TabController( + vsync: const TestVSync(), + length: tabs.length, + ); + + const Color tabBarThemeIndicatorColor = Color(0xffff0000); + + Widget buildTabBar({ required ThemeData theme }) { + return MaterialApp( + theme: theme, + home: Material( + child: Container( + alignment: Alignment.topLeft, + child: TabBar( + controller: controller, + tabs: tabs, + ), + ), + ), + ); + } + + await tester.pumpWidget(buildTabBar(theme: ThemeData(useMaterial3: true))); + + RenderBox tabBarBox = tester.firstRenderObject(find.byType(TabBar)); + expect(tabBarBox,paints..rrect(color: ThemeData(useMaterial3: true).colorScheme.primary)); + + await tester.pumpWidget(buildTabBar(theme: ThemeData( + useMaterial3: true, + tabBarTheme: const TabBarTheme(indicatorColor: tabBarThemeIndicatorColor) + ))); + await tester.pumpAndSettle(); + + tabBarBox = tester.firstRenderObject(find.byType(TabBar)); + expect(tabBarBox,paints..rrect(color: tabBarThemeIndicatorColor)); + }); + + testWidgets('Material2 - TabBar indicator respects TabBarTheme.indicatorColor', (WidgetTester tester) async { + final List tabs = List.generate(4, (int index) { + return Tab(text: 'Tab $index'); + }); + + final TabController controller = TabController( + vsync: const TestVSync(), + length: tabs.length, + ); + + const Color themeIndicatorColor = Color(0xffff0000); + const Color tabBarThemeIndicatorColor = Color(0xffffff00); + + Widget buildTabBar({ Color? themeIndicatorColor, Color? tabBarThemeIndicatorColor }) { + return MaterialApp( + theme: ThemeData( + indicatorColor: themeIndicatorColor, + tabBarTheme: TabBarTheme(indicatorColor: tabBarThemeIndicatorColor), + useMaterial3: false, + ), + home: Material( + child: Container( + alignment: Alignment.topLeft, + child: TabBar( + controller: controller, + tabs: tabs, + ), + ), + ), + ); + } + + await tester.pumpWidget(buildTabBar(themeIndicatorColor: themeIndicatorColor)); + + RenderBox tabBarBox = tester.firstRenderObject(find.byType(TabBar)); + expect(tabBarBox,paints..line(color: themeIndicatorColor)); + + await tester.pumpWidget(buildTabBar(tabBarThemeIndicatorColor: tabBarThemeIndicatorColor)); + await tester.pumpAndSettle(); + + tabBarBox = tester.firstRenderObject(find.byType(TabBar)); + expect(tabBarBox,paints..line(color: tabBarThemeIndicatorColor)); + }); } diff --git a/packages/flutter/test/material/tabs_test.dart b/packages/flutter/test/material/tabs_test.dart index 4b78963de5..1dc8234f5c 100644 --- a/packages/flutter/test/material/tabs_test.dart +++ b/packages/flutter/test/material/tabs_test.dart @@ -488,7 +488,6 @@ void main() { const double indicatorWeight = 3.0; - final RRect rrect = ui.ParagraphBuilder.shouldDisableRoundingHack ? RRect.fromLTRBAndCorners( 64.75,