No velocity detected when testing a swipe action in flutter

42 Views Asked by At

Given the following code:

GestureDetector(
  onHorizontalDragEnd: (DragEndDetails details) {
    if (details.primaryVelocity > 0) {
      // swiped to the right
    } else if (details.primaryVelocity < 0) {
      // swiped to the left
    }
  }
);

I am now trying to test this part:

var widget = MyWidgetWithTheGestureDetectorInside(); 
await tester.pumpWidget(widget);
TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(GestureDetector)));
await gesture.moveBy(const Offset(100, 0));
await gesture.up();
await tester.pumpAndSettle();

I also tried by using await tester.drag(...) instead. The outcome was always the same:

  • details.primaryVelocity was 0
  • details.velocity had 0 in each property as well (so no move at all)

When running the app in an emulator and doing the swipe on my own, the velocity has concrete values which allow me to identify the swipe direction.

So the question is: what the hell am I doing wrong here?

0

There are 0 best solutions below