diff --git a/packages/flutter/lib/src/widgets/scrollbar.dart b/packages/flutter/lib/src/widgets/scrollbar.dart index eb5d2f3af8..6fd683962b 100644 --- a/packages/flutter/lib/src/widgets/scrollbar.dart +++ b/packages/flutter/lib/src/widgets/scrollbar.dart @@ -1048,8 +1048,8 @@ class RawScrollbarState extends State with TickerProv final ScrollController? scrollController = widget.controller ?? PrimaryScrollController.of(context); final bool tryPrimary = widget.controller == null; final String controllerForError = tryPrimary - ? 'provided ScrollController' - : 'PrimaryScrollController'; + ? 'PrimaryScrollController' + : 'provided ScrollController'; String when = ''; if (showScrollbar) { diff --git a/packages/flutter/test/material/scrollbar_test.dart b/packages/flutter/test/material/scrollbar_test.dart index 9e36f25c80..8e67a725c6 100644 --- a/packages/flutter/test/material/scrollbar_test.dart +++ b/packages/flutter/test/material/scrollbar_test.dart @@ -1448,8 +1448,12 @@ void main() { ); } - Widget _buildApp({ ScrollController? scrollController }) { + Widget _buildApp({ + required String id, + ScrollController? scrollController, + }) { return MaterialApp( + key: ValueKey(id), home: DefaultTabController( length: 2, child: Scaffold( @@ -1465,33 +1469,37 @@ void main() { } // 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 // the transition. - try { - await tester.drag(find.text('Test').first, const Offset(10.0, 0.0)); - } on FlutterError catch (error) { - expect( - error.message, - contains('The Scrollbar attempted to paint using the position attached to the PrimaryScrollController.'), - ); - } + await tester.drag(find.text('Test').first, const Offset(-100.0, 0.0)); + await tester.pump(); + + FlutterError error = tester.takeException() as FlutterError; + expect( + error.message, + contains('The PrimaryScrollController is currently attached to more than one ScrollPosition.'), + ); // Asserts when using the ScrollController provided by the user. 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 // the transition. - try { - await tester.drag(find.text('Test').first, const Offset(10.0, 0.0)); - } on AssertionError catch (error) { - expect( - error.message, - contains('The Scrollbar attempted to paint using the position attached to the provided ScrollController.'), - ); - } + await tester.drag(find.text('Test').first, const Offset(-100.0, 0.0)); + await tester.pump(); + error = tester.takeException() as FlutterError; + expect( + error.message, + contains('The provided ScrollController is currently attached to more than one ScrollPosition.'), + ); }); testWidgets('Scrollbar scrollOrientation works correctly', (WidgetTester tester) async {