Unverified Commit 2aa1efcf authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Add regression test for TabBar crash (#144627)

This is a regression test for https://github.com/flutter/flutter/issues/144087 and https://github.com/flutter/flutter/issues/138588.

To be submitted after https://github.com/flutter/flutter/pull/144579.
parent ba7749a3
......@@ -6993,4 +6993,44 @@ void main() {
expect(tabTwoRect.right, moreOrLessEquals(tabTwoRight));
});
});
testWidgets('does not crash if switching to a newly added tab', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/144087.
Widget buildTabs(int tabCount) {
return boilerplate(
child: DefaultTabController(
length: tabCount,
child: Scaffold(
appBar: AppBar(
title: const Text('Flutter Demo Click Counter'),
bottom: TabBar(
tabAlignment: TabAlignment.start,
isScrollable: true,
tabs: List<Widget>.generate(tabCount, (int i) => Tab(text: 'Tab $i')),
),
),
body: TabBarView(
children: List<Widget>.generate(tabCount, (int i) => Text('View $i')),
),
),
),
);
}
await tester.pumpWidget(buildTabs(1));
expect(tester.widgetList(find.byType(Tab)), hasLength(1));
await tester.pumpWidget(buildTabs(2));
expect(tester.widgetList(find.byType(Tab)), hasLength(2));
await tester.pumpWidget(buildTabs(3));
expect(tester.widgetList(find.byType(Tab)), hasLength(3));
expect(find.text('View 0'), findsOneWidget);
expect(find.text('View 2'), findsNothing);
await tester.tap(find.text('Tab 2'));
await tester.pumpAndSettle();
expect(find.text('View 0'), findsNothing);
expect(find.text('View 2'), findsOneWidget);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment