Skip to content

Commit 2ea212d

Browse files
Create a WidgetTester extension to drag scroll bars (Resolves #22)
1 parent e070688 commit 2ea212d

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/flutter_test_robots.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ library flutter_test_robots;
33
export 'src/clipboard.dart';
44
export 'src/input_method_engine.dart';
55
export 'src/keyboard.dart';
6+
export 'src/scrollbar.dart';

lib/src/scrollbar.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'package:flutter/gestures.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
4+
/// Simulates the user interacting with a Scrollbar.
5+
extension ScrollbarInteractions on WidgetTester {
6+
/// Press a scrollbar thumb at [thumbLocation] and drag it vertically by [delta] pixels.
7+
Future<void> dragScrollbar(Offset thumbLocation, double delta) async {
8+
//Hover to make the thumb visible with a duration long enough to run the fade in animation.
9+
final testPointer = TestPointer(1, PointerDeviceKind.mouse);
10+
11+
await sendEventToBinding(testPointer.hover(thumbLocation, timeStamp: const Duration(seconds: 1)));
12+
await pumpAndSettle();
13+
14+
// Press the thumb.
15+
await sendEventToBinding(testPointer.down(thumbLocation));
16+
await pump(const Duration(milliseconds: 40));
17+
18+
// Move the thumb down.
19+
await sendEventToBinding(testPointer.move(thumbLocation + Offset(0, delta)));
20+
await pump();
21+
22+
// Release the pointer.
23+
await sendEventToBinding(testPointer.up());
24+
await pump();
25+
}
26+
}

0 commit comments

Comments
 (0)