Unverified Commit f4f1c210 authored by David Martos's avatar David Martos Committed by GitHub

Fix scrollbar error message and test (#84570)

parent a714c97c
...@@ -1048,8 +1048,8 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv ...@@ -1048,8 +1048,8 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
final ScrollController? scrollController = widget.controller ?? PrimaryScrollController.of(context); final ScrollController? scrollController = widget.controller ?? PrimaryScrollController.of(context);
final bool tryPrimary = widget.controller == null; final bool tryPrimary = widget.controller == null;
final String controllerForError = tryPrimary final String controllerForError = tryPrimary
? 'provided ScrollController' ? 'PrimaryScrollController'
: 'PrimaryScrollController'; : 'provided ScrollController';
String when = ''; String when = '';
if (showScrollbar) { if (showScrollbar) {
......
...@@ -1448,8 +1448,12 @@ void main() { ...@@ -1448,8 +1448,12 @@ void main() {
); );
} }
Widget _buildApp({ ScrollController? scrollController }) { Widget _buildApp({
required String id,
ScrollController? scrollController,
}) {
return MaterialApp( return MaterialApp(
key: ValueKey<String>(id),
home: DefaultTabController( home: DefaultTabController(
length: 2, length: 2,
child: Scaffold( child: Scaffold(
...@@ -1465,33 +1469,37 @@ void main() { ...@@ -1465,33 +1469,37 @@ void main() {
} }
// Asserts when using the PrimaryScrollController. // Asserts when using the PrimaryScrollController.
await tester.pumpWidget(_buildApp()); await tester.pumpWidget(_buildApp(id: 'PrimaryScrollController'));
// Swipe to the second tab, resulting in two attached ScrollPositions during // Swipe to the second tab, resulting in two attached ScrollPositions during
// the transition. // the transition.
try { await tester.drag(find.text('Test').first, const Offset(-100.0, 0.0));
await tester.drag(find.text('Test').first, const Offset(10.0, 0.0)); await tester.pump();
} on FlutterError catch (error) {
expect( FlutterError error = tester.takeException() as FlutterError;
error.message, expect(
contains('The Scrollbar attempted to paint using the position attached to the PrimaryScrollController.'), error.message,
); contains('The PrimaryScrollController is currently attached to more than one ScrollPosition.'),
} );
// Asserts when using the ScrollController provided by the user. // Asserts when using the ScrollController provided by the user.
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
await tester.pumpWidget(_buildApp(scrollController: scrollController)); await tester.pumpWidget(
_buildApp(
id: 'Provided ScrollController',
scrollController: scrollController,
),
);
// Swipe to the second tab, resulting in two attached ScrollPositions during // Swipe to the second tab, resulting in two attached ScrollPositions during
// the transition. // the transition.
try { await tester.drag(find.text('Test').first, const Offset(-100.0, 0.0));
await tester.drag(find.text('Test').first, const Offset(10.0, 0.0)); await tester.pump();
} on AssertionError catch (error) { error = tester.takeException() as FlutterError;
expect( expect(
error.message, error.message,
contains('The Scrollbar attempted to paint using the position attached to the provided ScrollController.'), contains('The provided ScrollController is currently attached to more than one ScrollPosition.'),
); );
}
}); });
testWidgets('Scrollbar scrollOrientation works correctly', (WidgetTester tester) async { testWidgets('Scrollbar scrollOrientation works correctly', (WidgetTester tester) async {
......
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