restoreSnapshotAnimated method
Like restoreSnapshot but smoothly reverses the in-session
transforms instead of snapping them. Data state snaps synchronously
(callers — including the host — see the restored values immediately);
the render-side animator interpolates the visual rotate / pan /
scale back to the snapshot, and a session-flip plays its card-flip
arc in reverse. CropScreen._cancel fires this unawaited and
then pops, so the reverse overlaps with the screen's pop transition.
The crop rect is snapped — animating an arbitrary Rect doesn't
compose well with the rest of the reverse and crop-rect changes
are rarely what users undo.
Implementation
Future<void> restoreSnapshotAnimated() async {
final s = _snapshot;
if (s == null) return;
_revertSession = null;
rotationScaleFloor = null;
_settleAnimator.cancel();
crop = s.crop;
final flipChanged = s.imageTransform.flipX != imageTransform.flipX;
final preRender = _renderTransform.clone();
_suppressMirror = true;
imageTransform.update(s.imageTransform);
_suppressMirror = false;
_renderTransform.update(preRender);
_renderTransform.flipX = s.imageTransform.flipX;
notifyListeners();
if (flipChanged) {
_flipDecoration = dartmath.pi;
_flipAnimator.animate(target: 0);
}
await _renderAnimator.animate(target: s.imageTransform);
final flipX = _renderTransform.flipX;
_renderTransform.update(s.imageTransform);
_renderTransform.flipX = flipX;
notifyListeners();
}