Unverified Commit abe67b4a authored by stuartmorgan's avatar stuartmorgan Committed by GitHub

Don't enable scroll wheel when scrolling is off (#37211)

NeverScrollableScrollPhysics should prevent all scrolling, but the new
scrollwheel codepath wasn't checking it.

Fixes #35304
parent 2b1db6c1
......@@ -547,6 +547,9 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin
void _handlePointerScroll(PointerEvent event) {
assert(event is PointerScrollEvent);
if (_physics != null && !_physics.shouldAcceptUserOffset(position)) {
return;
}
final double targetScrollOffset = _targetScrollOffsetForPointerScroll(event);
if (targetScrollOffset != position.pixels) {
position.jumpTo(targetScrollOffset);
......
......@@ -8,13 +8,14 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
Future<void> pumpTest(WidgetTester tester, TargetPlatform platform) async {
Future<void> pumpTest(WidgetTester tester, TargetPlatform platform, {bool scrollable = true}) async {
await tester.pumpWidget(MaterialApp(
theme: ThemeData(
platform: platform,
),
home: const CustomScrollView(
slivers: <Widget>[
home: CustomScrollView(
physics: scrollable ? null : const NeverScrollableScrollPhysics(),
slivers: const <Widget>[
SliverToBoxAdapter(child: SizedBox(height: 2000.0)),
],
),
......@@ -236,4 +237,15 @@ void main() {
await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, -30.0)), result);
expect(getScrollOffset(tester), 0.0);
});
testWidgets('Scroll pointer signals are ignored when scrolling is disabled', (WidgetTester tester) async {
await pumpTest(tester, TargetPlatform.fuchsia, scrollable: false);
final Offset scrollEventLocation = tester.getCenter(find.byType(Viewport));
final TestPointer testPointer = TestPointer(1, ui.PointerDeviceKind.mouse);
// Create a hover event so that |testPointer| has a location when generating the scroll.
testPointer.hover(scrollEventLocation);
final HitTestResult result = tester.hitTestOnBinding(scrollEventLocation);
await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, 20.0)), result);
expect(getScrollOffset(tester), 0.0);
});
}
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