* Crash when a TabBar is put in a BottomAppBar.

* Tabs bugs (e.g. crash on transparent material)

- Tabs would crash when placed on transparent Materials
- Tabs would fail to render the child if an icon was specified
This commit is contained in:
Ian Hickson 2019-02-04 15:11:07 -08:00 committed by GitHub
parent 53ea2fd123
commit 7b618005c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 2 deletions

View File

@ -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<TabBar> {
// 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(

View File

@ -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<RenderParagraph>(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<RenderParagraph>(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<RenderParagraph>(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 <Widget>[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 <Widget>[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 <Widget>[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<String> tabs = <String>['A', 'B', 'C'];