Future<Null> flingFrom(Point startLocation, Offset offset, double velocity, { int pointer: 1, Duration frameInterval: const Duration(milliseconds: 16) })

Attempts a fling gesture starting from the given location, moving the given distance, reaching the given velocity.

Exactly 50 pointer events are synthesized.

The offset and velocity control the interval between each pointer event. For example, if the offset is 200 pixels, and the velocity is 800 pixels per second, the pointer events will be sent for each increment of 4 pixels (200/50), over 250ms (200/800), meaning events will be sent every 1.25ms (250/200).

To make tests more realistic, frames may be pumped during this time (using calls to pump). If the total duration is longer than frameInterval, then one frame is pumped each time that amount of time elapses while sending events, or each time an event is synthesised, whichever is rarer.

Source

Future<Null> flingFrom(Point startLocation, Offset offset, double velocity, { int pointer: 1, Duration frameInterval: const Duration(milliseconds: 16) }) {
  return TestAsyncUtils.guard(() async {
    assert(offset.distance > 0.0);
    assert(velocity != 0.0);   // velocity is pixels/second
    final TestPointer p = new TestPointer(pointer);
    final HitTestResult result = hitTestOnBinding(startLocation);
    const int kMoveCount = 50; // Needs to be >= kHistorySize, see _LeastSquaresVelocityTrackerStrategy
    final double timeStampDelta = 1000.0 * offset.distance / (kMoveCount * velocity);
    double timeStamp = 0.0;
    double lastTimeStamp = timeStamp;
    await sendEventToBinding(p.down(startLocation, timeStamp: new Duration(milliseconds: timeStamp.round())), result);
    for (int i = 0; i <= kMoveCount; i += 1) {
      final Point location = startLocation + Offset.lerp(Offset.zero, offset, i / kMoveCount);
      await sendEventToBinding(p.move(location, timeStamp: new Duration(milliseconds: timeStamp.round())), result);
      timeStamp += timeStampDelta;
      if (timeStamp - lastTimeStamp > frameInterval.inMilliseconds) {
        await pump(new Duration(milliseconds: (timeStamp - lastTimeStamp).truncate()));
        lastTimeStamp = timeStamp;
      }
    }
    await sendEventToBinding(p.up(timeStamp: new Duration(milliseconds: timeStamp.round())), result);
    return null;
  });
}