Skip to content

Commit

Permalink
[Scrollbar]Skip the ScrollPosition check if the bar was unmounted (#1…
Browse files Browse the repository at this point in the history
…03948)
  • Loading branch information
xu-baolin authored May 19, 2022
1 parent 80a51e4 commit 93211a4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/flutter/lib/src/widgets/scrollbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,9 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
}

bool _debugCheckHasValidScrollPosition() {
if (!mounted) {
return true;
}
final ScrollController? scrollController = widget.controller ?? PrimaryScrollController.of(context);
final bool tryPrimary = widget.controller == null;
final String controllerForError = tryPrimary
Expand Down
38 changes: 38 additions & 0 deletions packages/flutter/test/widgets/scrollbar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2444,4 +2444,42 @@ void main() {
}
expect(() => tester.pumpWidget(buildApp()), throwsAssertionError);
});

testWidgets('Skip the ScrollPosition check if the bar was unmounted', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/103939
final ScrollController scrollController = ScrollController();
Widget buildApp(bool buildBar) {
return Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: MediaQueryData(
invertColors: buildBar, // Trigger a post frame check before unmount.
),
child: PrimaryScrollController(
controller: scrollController,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
Widget content = const SingleChildScrollView(
child: SizedBox(width: 4000.0, height: 4000.0),
);
if (buildBar) {
content = RawScrollbar(
thumbVisibility: true,
child: content,
);
}
return content;
},
),
),
),
);
}

await tester.pumpWidget(buildApp(true));

await tester.pumpWidget(buildApp(false));

// Go without throw.
});
}

0 comments on commit 93211a4

Please sign in to comment.