animateToLevel method
Settles every item on target with a spring, carrying velocity
(levels/second). Per-item levels are cleared.
Anchors the first visible item unless anchor is false or an anchor is
already active (e.g. from a pinch). animate overrides reduceMotion.
Implementation
Future<void> animateToLevel(
int target, {
double velocity = 0,
bool anchor = true,
bool? animate,
}) async {
target = target.clamp(0, maxLevel);
if (anchor && !_anchorBusy) anchorLeading();
_pinchAnchored = false;
final animated = animate ?? !reduceMotion;
_clearItems(animate: animated);
_commit(target);
final end = target.toDouble();
if (!animated) {
_zoom.value = end;
releaseAnchor();
return;
}
await _zoom
.animateWith(SpringSimulation(spring, _zoom.value, end, velocity))
.orCancel
.then((_) => releaseAnchor(), onError: (Object _) {});
}