ensureSource method
Eagerly decode input.file and cache it as source. Idempotent.
Returns null for non-image media. Required by ComposePage so
the compose-page preview can paint via the same camera matrix the
tool screens use — otherwise compose's BoxFit.contain against
the full body would land the image at a different on-screen rect
than tool screens' camera-driven render, producing a visible jump
(the "shrink-then-enlarge" boundary) on entering crop / draw.
Implementation
Future<ui.Image?> ensureSource() async {
if (input is! ImageMedia) return null;
if (_source != null) return _source;
final decoded = await _decodeFile(input.file);
if (disposed) {
decoded?.dispose();
return null;
}
if (_source != null) {
decoded?.dispose();
return _source;
}
_source = decoded;
final src = sourceSize;
if (src != null && !fitRect.value.isEmpty) {
cameraAnimator.cancel();
final fit = _fitOf(fitRect.value, _cameraContentRect);
_animatedFit = fit;
camera.value = fit.toMatrix();
}
notifyListeners();
return _source;
}