|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be
|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
| 5 | +import 'dart:ui' as ui; |
| 6 | + |
5 | 7 | import 'package:flutter/widgets.dart';
|
6 | 8 | import 'package:flutter_test/flutter_test.dart';
|
7 | 9 |
|
@@ -362,4 +364,33 @@ void main() {
|
362 | 364 | expect(tester.getTopLeft(find.widgetWithText(SizedBox, 'Item 1')), Offset.zero);
|
363 | 365 |
|
364 | 366 | });
|
| 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 | + }); |
365 | 396 | }
|
0 commit comments