Fixed preferredSize getter in TabBar (#41299)

This commit is contained in:
Anthony Mansour 2020-02-12 11:53:02 -05:00 committed by GitHub
parent 1903ce012e
commit 4c1045c0f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -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);
}
}

View file

@ -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<Widget> tabListWithText = <Widget>[
Tab(icon: Icon(Icons.notifications), text: 'Test'),
];
const List<Widget> tabListWithTextChild = <Widget>[
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);
});
}