From 000f4d1590322cc229072a6e9616051cab074286 Mon Sep 17 00:00:00 2001 From: chunhtai <47866232+chunhtai@users.noreply.github.com> Date: Tue, 29 Mar 2022 13:05:09 -0700 Subject: [PATCH] Allow unknown device kind to scroll scrollables (#100800) --- .../lib/src/widgets/scroll_configuration.dart | 3 ++ .../test/widgets/scroll_behavior_test.dart | 1 + .../flutter/test/widgets/scrollable_test.dart | 29 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/packages/flutter/lib/src/widgets/scroll_configuration.dart b/packages/flutter/lib/src/widgets/scroll_configuration.dart index 7b0a85b5ef..947efaac38 100644 --- a/packages/flutter/lib/src/widgets/scroll_configuration.dart +++ b/packages/flutter/lib/src/widgets/scroll_configuration.dart @@ -19,6 +19,9 @@ const Set _kTouchLikeDeviceTypes = { PointerDeviceKind.touch, PointerDeviceKind.stylus, PointerDeviceKind.invertedStylus, + // The VoiceAccess sends pointer events with unknown type when scrolling + // scrollables. + PointerDeviceKind.unknown, }; /// The default overscroll indicator applied on [TargetPlatform.android]. diff --git a/packages/flutter/test/widgets/scroll_behavior_test.dart b/packages/flutter/test/widgets/scroll_behavior_test.dart index a1f6afa0a2..99a97a8c17 100644 --- a/packages/flutter/test/widgets/scroll_behavior_test.dart +++ b/packages/flutter/test/widgets/scroll_behavior_test.dart @@ -134,6 +134,7 @@ void main() { PointerDeviceKind.touch, PointerDeviceKind.stylus, PointerDeviceKind.invertedStylus, + PointerDeviceKind.unknown, }); // Use copyWith to modify drag devices diff --git a/packages/flutter/test/widgets/scrollable_test.dart b/packages/flutter/test/widgets/scrollable_test.dart index 1e21d2ba87..99082034bd 100644 --- a/packages/flutter/test/widgets/scrollable_test.dart +++ b/packages/flutter/test/widgets/scrollable_test.dart @@ -1273,6 +1273,35 @@ void main() { expect(tester.takeException(), null); }); + testWidgets('Accepts drag with unknown device kind by default', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/90912. + await tester.pumpWidget( + const MaterialApp( + home: CustomScrollView( + slivers: [ + SliverToBoxAdapter(child: SizedBox(height: 2000.0)), + ], + ), + ) + ); + final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Scrollable), warnIfMissed: true), kind: ui.PointerDeviceKind.unknown); + expect(getScrollOffset(tester), 0.0); + await gesture.moveBy(const Offset(0.0, -200)); + await tester.pump(); + await tester.pumpAndSettle(); + + expect(getScrollOffset(tester), 200); + + await gesture.moveBy(const Offset(0.0, 200)); + await tester.pump(); + await tester.pumpAndSettle(); + + expect(getScrollOffset(tester), 0.0); + + await gesture.removePointer(); + await tester.pump(); + }, variant: const TargetPlatformVariant({ TargetPlatform.iOS, TargetPlatform.macOS, TargetPlatform.android })); + testWidgets('Does not scroll with mouse pointer drag when behavior is configured to ignore them', (WidgetTester tester) async { await pumpTest(tester, debugDefaultTargetPlatformOverride, enableMouseDrag: false); final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Scrollable), warnIfMissed: true), kind: ui.PointerDeviceKind.mouse);