tick method
Advances everything to now (in seconds; the same clock as touch
times). Returns whether anything is still moving.
Implementation
bool tick(double now) {
if (!_started) {
_started = true;
_now = now;
}
final double elapsed = math.max(now - _now, 0.0);
double start =
now - (_idle ? math.min(elapsed, _firstStep) : math.min(elapsed, 0.1));
// Touch times: ignore any on another clock; a resting bar starts from
// the earliest touch.
double? timeOf(_TouchEvent e) {
final double? t = e.time;
return t == null || t < now - 0.1 || t > now + 0.05 ? null : t;
}
if (_idle) {
for (final _TouchEvent e in _pending) {
final double? t = timeOf(e);
if (t != null) {
start = math.min(start, math.max(t, now - 0.05));
}
}
}
var t = start;
for (final _TouchEvent e in _pending) {
final double te = (timeOf(e) ?? (start + now) / 2).clamp(t, now);
_advance(t, te);
_apply(e, te);
t = te;
}
_pending.clear();
_advance(t, now);
_now = now;
// The finger's speed along the bar, from where the lens belonged over
// the last 50ms of frames: it falls to zero as soon as the finger rests.
if (_touch != null) {
_history.addLast((now, _lensAnchor));
while (_history.length > 2 && now - _history.first.$1 > 0.05) {
_history.removeFirst();
}
_anchorVelocity = _slope(_history);
}
_idle = !isActive;
debugOnTick?.call(this, now);
return !_idle;
}