diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index a8364d7127..92ae8ca9e8 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -753,7 +753,7 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget { for (final Widget item in tabs) { if (item is Tab) { final Tab tab = item; - if (tab.text != null && tab.icon != null) + if ((tab.text != null || tab.child != null) && tab.icon != null) return Size.fromHeight(_kTextAndIconTabHeight + indicatorWeight); } } diff --git a/packages/flutter/test/material/tabs_test.dart b/packages/flutter/test/material/tabs_test.dart index 9796ef610d..bba9e19ad5 100644 --- a/packages/flutter/test/material/tabs_test.dart +++ b/packages/flutter/test/material/tabs_test.dart @@ -2459,4 +2459,20 @@ void main() { await tester.pumpAndSettle(); expect(find.text('No tabs'), findsOneWidget); }); + + testWidgets('TabBar expands vertically to accommodate the Icon and child Text() pair the same amount it would expand for Icon and text pair.', (WidgetTester tester) async { + const double indicatorWeight = 2.0; + + const List tabListWithText = [ + Tab(icon: Icon(Icons.notifications), text: 'Test'), + ]; + const List tabListWithTextChild = [ + Tab(icon: Icon(Icons.notifications), child: Text('Test')), + ]; + + const TabBar tabBarWithText = TabBar(tabs: tabListWithText, indicatorWeight: indicatorWeight,); + const TabBar tabBarWithTextChild = TabBar(tabs: tabListWithTextChild, indicatorWeight: indicatorWeight,); + + expect(tabBarWithText.preferredSize, tabBarWithTextChild.preferredSize); + }); }