Skip to content

Commit

Permalink
Create a WidgetTester extension to drag scroll bars (Resolves Flutter…
Browse files Browse the repository at this point in the history
  • Loading branch information
angelosilvestre committed Jan 8, 2024
1 parent e070688 commit 2ea212d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/flutter_test_robots.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ library flutter_test_robots;
export 'src/clipboard.dart';
export 'src/input_method_engine.dart';
export 'src/keyboard.dart';
export 'src/scrollbar.dart';
26 changes: 26 additions & 0 deletions lib/src/scrollbar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/gestures.dart';
import 'package:flutter_test/flutter_test.dart';

/// Simulates the user interacting with a Scrollbar.
extension ScrollbarInteractions on WidgetTester {
/// Press a scrollbar thumb at [thumbLocation] and drag it vertically by [delta] pixels.
Future<void> dragScrollbar(Offset thumbLocation, double delta) async {
//Hover to make the thumb visible with a duration long enough to run the fade in animation.
final testPointer = TestPointer(1, PointerDeviceKind.mouse);

await sendEventToBinding(testPointer.hover(thumbLocation, timeStamp: const Duration(seconds: 1)));
await pumpAndSettle();

// Press the thumb.
await sendEventToBinding(testPointer.down(thumbLocation));
await pump(const Duration(milliseconds: 40));

// Move the thumb down.
await sendEventToBinding(testPointer.move(thumbLocation + Offset(0, delta)));
await pump();

// Release the pointer.
await sendEventToBinding(testPointer.up());
await pump();
}
}

0 comments on commit 2ea212d

Please sign in to comment.