diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index abd89c9e4a..a687324cc8 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -95,7 +95,7 @@ class Tab extends StatelessWidget { if (icon == null) { height = _kTabHeight; label = _buildLabelText(); - } else if (text == null) { + } else if (text == null && child == null) { height = _kTabHeight; label = icon; } else { @@ -730,7 +730,10 @@ class _TabBarState extends State { // When that happens, automatic transitions of the theme will likely look // ugly as the indicator color suddenly snaps to white at one end, but it's // not clear how to avoid that any further. - if (color.value == Material.of(context).color.value) + // + // The material's color might be null (if it's a transparency). In that case + // there's no good way for us to find out what the color is so we don't. + if (color.value == Material.of(context).color?.value) color = Colors.white; return UnderlineTabIndicator( diff --git a/packages/flutter/test/material/tabs_test.dart b/packages/flutter/test/material/tabs_test.dart index 69742c534a..3d81d1b343 100644 --- a/packages/flutter/test/material/tabs_test.dart +++ b/packages/flutter/test/material/tabs_test.dart @@ -186,6 +186,68 @@ void main() { debugResetSemanticsIdCounter(); }); + testWidgets('Tab sizing - icon', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp(home: Center(child: Material(child: Tab(icon: SizedBox(width: 10.0, height: 10.0))))), + ); + expect(tester.getSize(find.byType(Tab)), const Size(10.0, 46.0)); + }); + + testWidgets('Tab sizing - child', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp(home: Center(child: Material(child: Tab(child: SizedBox(width: 10.0, height: 10.0))))), + ); + expect(tester.getSize(find.byType(Tab)), const Size(10.0, 46.0)); + }); + + testWidgets('Tab sizing - text', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp(theme: ThemeData(fontFamily: 'Ahem'), home: const Center(child: Material(child: Tab(text: 'x')))), + ); + expect(tester.renderObject(find.byType(RichText)).text.style.fontFamily, 'Ahem'); + expect(tester.getSize(find.byType(Tab)), const Size(14.0, 46.0)); + }); + + testWidgets('Tab sizing - icon and text', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp(theme: ThemeData(fontFamily: 'Ahem'), home: const Center(child: Material(child: Tab(icon: SizedBox(width: 10.0, height: 10.0), text: 'x')))), + ); + expect(tester.renderObject(find.byType(RichText)).text.style.fontFamily, 'Ahem'); + expect(tester.getSize(find.byType(Tab)), const Size(14.0, 72.0)); + }); + + testWidgets('Tab sizing - icon and child', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp(theme: ThemeData(fontFamily: 'Ahem'), home: const Center(child: Material(child: Tab(icon: SizedBox(width: 10.0, height: 10.0), child: Text('x'))))), + ); + expect(tester.renderObject(find.byType(RichText)).text.style.fontFamily, 'Ahem'); + expect(tester.getSize(find.byType(Tab)), const Size(14.0, 72.0)); + }); + + testWidgets('Tab color - normal', (WidgetTester tester) async { + final Widget tabBar = TabBar(tabs: const [SizedBox.shrink()], controller: TabController(length: 1, vsync: tester)); + await tester.pumpWidget( + MaterialApp(home: Material(child: tabBar)), + ); + expect(find.byType(TabBar), paints..line(color: Colors.blue[500])); + }); + + testWidgets('Tab color - match', (WidgetTester tester) async { + final Widget tabBar = TabBar(tabs: const [SizedBox.shrink()], controller: TabController(length: 1, vsync: tester)); + await tester.pumpWidget( + MaterialApp(home: Material(color: const Color(0xff2196f3), child: tabBar)), + ); + expect(find.byType(TabBar), paints..line(color: Colors.white)); + }); + + testWidgets('Tab color - transparency', (WidgetTester tester) async { + final Widget tabBar = TabBar(tabs: const [SizedBox.shrink()], controller: TabController(length: 1, vsync: tester)); + await tester.pumpWidget( + MaterialApp(home: Material(type: MaterialType.transparency, child: tabBar)), + ); + expect(find.byType(TabBar), paints..line(color: Colors.blue[500])); + }); + testWidgets('TabBar tap selects tab', (WidgetTester tester) async { final List tabs = ['A', 'B', 'C'];