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
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) {
......
......@@ -1448,8 +1448,12 @@ void main() {
);
}
Widget _buildApp({ ScrollController? scrollController }) {
Widget _buildApp({
required String id,
ScrollController? scrollController,
}) {
return MaterialApp(
key: ValueKey<String>(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) {
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 Scrollbar attempted to paint using the position attached to the PrimaryScrollController.'),
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) {
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 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 {
......
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