createBallisticSimulation method

  1. @override
Simulation createBallisticSimulation (ScrollMetrics position, double velocity)
override

Returns a simulation for ballistic scrolling starting from the given position with the given velocity.

This is used by ScrollPositionWithSingleContext in the ScrollPositionWithSingleContext.goBallistic method. If the result is non-null, ScrollPositionWithSingleContext will begin a BallisticScrollActivity with the returned value. Otherwise, it will begin an idle activity instead.

The given position is only valid during this method call. Do not keep a reference to it to use later, as the values may update, may not update, or may update to reflect an entirely unrelated scrollable.

Implementation

@override
Simulation createBallisticSimulation(ScrollMetrics position, double velocity) {
  final Tolerance tolerance = this.tolerance;
  if (velocity.abs() >= tolerance.velocity || position.outOfRange) {
    return BouncingScrollSimulation(
      spring: spring,
      position: position.pixels,
      velocity: velocity * 0.91, // TODO(abarth): We should move this constant closer to the drag end.
      leadingExtent: position.minScrollExtent,
      trailingExtent: position.maxScrollExtent,
      tolerance: tolerance,
    );
  }
  return null;
}