Skip to content

Commit 806fb93

Browse files
authored
Fix ScrollPosition.isScrollingNotifier.value for pointer scrolling (#113972)
1 parent 694b253 commit 806fb93

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

packages/flutter/lib/src/widgets/scroll_position.dart

-2
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,6 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
810810
///
811811
/// This method is very similar to [jumpTo], but [pointerScroll] will
812812
/// update the [ScrollDirection].
813-
///
814-
// TODO(YeungKC): Support trackpad scroll, https://github.com/flutter/flutter/issues/23604.
815813
void pointerScroll(double delta);
816814

817815
/// Calls [jumpTo] if duration is null or [Duration.zero], otherwise

packages/flutter/lib/src/widgets/scroll_position_with_single_context.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ class ScrollPositionWithSingleContext extends ScrollPosition implements ScrollAc
222222
-delta > 0.0 ? ScrollDirection.forward : ScrollDirection.reverse,
223223
);
224224
final double oldPixels = pixels;
225-
forcePixels(targetPixels);
225+
// Set the notifier before calling force pixels.
226+
// This is set to false again after going ballistic below.
226227
isScrollingNotifier.value = true;
228+
forcePixels(targetPixels);
227229
didStartScroll();
228230
didUpdateScrollPositionBy(pixels - oldPixels);
229231
didEndScroll();

packages/flutter/test/widgets/scroll_controller_test.dart

+31
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:ui' as ui;
6+
57
import 'package:flutter/widgets.dart';
68
import 'package:flutter_test/flutter_test.dart';
79

@@ -362,4 +364,33 @@ void main() {
362364
expect(tester.getTopLeft(find.widgetWithText(SizedBox, 'Item 1')), Offset.zero);
363365

364366
});
367+
368+
testWidgets('isScrollingNotifier works with pointer scroll', (WidgetTester tester) async {
369+
Widget buildFrame(ScrollController controller) {
370+
return Directionality(
371+
textDirection: TextDirection.ltr,
372+
child: ListView(
373+
controller: controller,
374+
children: List<Widget>.generate(50, (int index) {
375+
return SizedBox(height: 100.0, child: Text('Item $index'));
376+
}).toList(),
377+
),
378+
);
379+
}
380+
381+
bool isScrolling = false;
382+
final ScrollController controller = ScrollController();
383+
controller.addListener((){
384+
isScrolling = controller.position.isScrollingNotifier.value;
385+
});
386+
await tester.pumpWidget(buildFrame(controller));
387+
final Offset scrollEventLocation = tester.getCenter(find.byType(ListView));
388+
final TestPointer testPointer = TestPointer(1, ui.PointerDeviceKind.mouse);
389+
// Create a hover event so that |testPointer| has a location when generating the scroll.
390+
testPointer.hover(scrollEventLocation);
391+
await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, 300.0)));
392+
// When the listener was notified, the value of the isScrollingNotifier
393+
// should have been true
394+
expect(isScrolling, isTrue);
395+
});
365396
}

0 commit comments

Comments
 (0)