ChartVelocityTracker class

Measures the velocity of each pointer of a touch gesture, standing in for Android's VelocityTracker.

Feed it every ChartTouchEvent of the gesture with addMovement, then call computeCurrentVelocity and read getXVelocity / getYVelocity per pointer id. Each pointer is tracked by one of Flutter's VelocityTrackers (least squares over the last 100 ms, like Android's default strategy).

Which events add a sample follows Android: a down clears every pointer, a pointer down starts the new pointer's trace over, and moves add the position of every pointer. Ups and pointer ups add nothing, so the velocity of a lifted pointer stays as it was, except that an up that comes more than 40 ms after the previous event clears every pointer (the fingers had stopped). Cancels are ignored.

Flutter's tracker reads the gesture binding's sampling clock, which every Flutter app has; a test without a widget calls TestWidgetsFlutterBinding.ensureInitialized() first.

Constructors

ChartVelocityTracker()
Creates an empty tracker, VelocityTracker.obtain().

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

addMovement(ChartTouchEvent event) → void
Adds the pointer positions of event to the tracked movement, VelocityTracker.addMovement(MotionEvent).
clear() → void
Forgets all tracked movement and computed velocities, VelocityTracker.clear().
computeCurrentVelocity(int units, [double maxVelocity = double.maxFinite]) → void
Computes the current velocity of every tracked pointer, VelocityTracker.computeCurrentVelocity(units, max).
getXVelocity(int pointerId) → double
The x velocity of the pointer with pointerId from the last computeCurrentVelocity, 0 when it is not tracked, VelocityTracker.getXVelocity(id).
getYVelocity(int pointerId) → double
The y velocity of the pointer with pointerId from the last computeCurrentVelocity, 0 when it is not tracked, VelocityTracker.getYVelocity(id).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
recycle() → void
Releases the tracker, VelocityTracker.recycle(). Here the same as clear; there is no pool.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

pointerUpCleanUpIfNecessary(ChartTouchEvent ev, ChartVelocityTracker tracker) → void
Clears tracker when the pointer that was lifted in ev moved in the opposite direction of another pointer, so a pinch does not end in a fling. Kotlin's Utils.velocityTrackerPointerUpCleanUpIfNecessary.