Unverified Commit 541a8bfd authored by Bruno Leroux's avatar Bruno Leroux Committed by GitHub

Fix switching from scrollable and non-scrollable tab bars throws (#120771)

Co-authored-by: 's avatarBruno Leroux <bruno.leroux@gmail.com>
parent 78657136
...@@ -1142,7 +1142,7 @@ class _TabBarState extends State<TabBar> { ...@@ -1142,7 +1142,7 @@ class _TabBarState extends State<TabBar> {
_updateTabController(); _updateTabController();
_initIndicatorPainter(); _initIndicatorPainter();
// Adjust scroll position. // Adjust scroll position.
if (_scrollController != null) { if (_scrollController != null && _scrollController!.hasClients) {
final ScrollPosition position = _scrollController!.position; final ScrollPosition position = _scrollController!.position;
if (position is _TabBarScrollPosition) { if (position is _TabBarScrollPosition) {
position.markNeedsPixelsCorrection(); position.markNeedsPixelsCorrection();
......
...@@ -3568,6 +3568,46 @@ void main() { ...@@ -3568,6 +3568,46 @@ void main() {
expect(tester.getCenter(find.byKey(lastTabKey)).dx, equals(750.0)); expect(tester.getCenter(find.byKey(lastTabKey)).dx, equals(750.0));
}); });
testWidgets('Do not throw when switching beetween a scrollable TabBar and a non-scrollable TabBar', (WidgetTester tester) async {
// This is a regression test for https://github.com/flutter/flutter/issues/120649
final TabController controller1 = TabController(
vsync: const TestVSync(),
length: 2,
);
final TabController controller2 = TabController(
vsync: const TestVSync(),
length: 2,
);
Widget buildFrame(TabController controller, bool isScrollable) {
return boilerplate(
child: Container(
alignment: Alignment.topLeft,
child: TabBar(
controller: controller,
isScrollable: isScrollable,
tabs: const <Tab>[
Tab(text: 'LEFT'),
Tab(text: 'RIGHT'),
],
),
),
);
}
// Show both controllers once.
await tester.pumpWidget(buildFrame(controller1, false));
await tester.pumpWidget(buildFrame(controller2, true));
// Switch back to the first controller.
await tester.pumpWidget(buildFrame(controller1, false));
expect(tester.takeException(), null);
// Switch back to the second controller.
await tester.pumpWidget(buildFrame(controller2, true));
expect(tester.takeException(), null);
});
testWidgets('Default tab indicator color is white', (WidgetTester tester) async { testWidgets('Default tab indicator color is white', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/15958 // Regression test for https://github.com/flutter/flutter/issues/15958
final List<String> tabs = <String>['LEFT', 'RIGHT']; final List<String> tabs = <String>['LEFT', 'RIGHT'];
......
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