ComposeEntry class

Per-asset view-model for the media compose pipeline. Owns the caption controller, viewer transform, video controller, the lazily decoded source image, the persistent editor layers (vector state, survives across tool re-entries), and a cached rendered preview.

Both ComposePage (one or many) and tests consume entries; the chrome rebinds its composer + edit toolbar to the focused entry. Mirrors telegram-iOS's per-item state in TGMediaEditingContext (per-item caption + adjustments, shared chrome on top).

Mixed-in types
Available extensions

Constructors

ComposeEntry({required XMedia input, Object? sourceId, Size? contentSize})
Creates the entry of input; contentSize is the picker's size hint.

Properties

camera → ValueEmitter<Matrix4>
Host-owned viewport-fitting matrix shared across compose / crop / draw. Layers paint against this; gestures read its scale. Top-left origin: camera · (0, 0) lands at image-top-left in viewport space (telegram convention).
latefinal
cameraAnimator → Animator<CameraFit>
Animates camera between fits.
latefinal
composerController → TextEditingController
The caption's text, from the host's caption controller.
final
contentScreenRect → Rect?
Screen rect (editor-surface coords) the visible content occupies at the current camera fit: _cameraContentRect aspect-fit and centered in fitRect — where the preview paints at rest. The open / close hero morphs anchor here. Null until the source is decoded and the fit rect measured.
no setter
contentSize → Size?
Best-known intrinsic dimensions of the VISIBLE content: the crop rect once a crop layer exists (what the preview shows and the close-morph snapshot rasterises), the decoded source otherwise, the asset-side hint until decode.
no setter
cropLayer ↔ CropImageLayer?
Persistent editor layers. Created lazily on first tool open; state lives in the layer instances themselves so it survives across re-entries. The layer's own saveSnapshot / restoreSnapshot handles tool-cancel rollback.
getter/setter pair
cropOutputCamera → Matrix4
camera re-anchored for crop-OUTPUT-space content: the rendered image preview and the cropped-video pipeline lay out with the crop rect's top-left at their origin, so they paint through camera · translate(crop.topLeft) to land exactly where the camera fits the crop rect. Reduces to camera while uncropped.
no setter
disposed → bool
Whether dispose has already run.
no setterinherited
drawLayer ↔ DrawImageLayer?
The draw tool's strokes; absent until the draw tool first opens.
getter/setter pair
entityLayer ↔ EntityLayer?
The text overlays; absent until the draw tool first opens.
getter/setter pair
fitRect → ValueEmitter<Rect>
Where in the editor surface (scaffold-body coords) the image should fit. Each screen pushes its own rect via setFitRect from its onActive lifecycle: compose's rect excludes the floating top bar + bottom strip; tool screens' rects exclude their floating chrome. Because all three screens render the editor full-bleed in the same coord system, the matrix interpolates smoothly across transitions (both scale AND position animate, not just scale).
latefinal
hasEdits → bool
True when at least one tool has been applied to an IMAGE (used by the page's submit handler to decide whether to rasterise on send). A video's crop is not rasterised — it rides videoEdit.crop to the send-time export — so this stays image-only.
no setter
hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether there is at least one active listener.
no setterinherited
input → XMedia
The asset as picked / captured / pasted. Never mutated.
final
isZoomed → ValueNotifier<bool>
Whether the preview is zoomed in.
final
renderedPreview ↔ Image?
Cached rendered preview (source + layer adjustments applied). Null when no edits have been applied yet — the preview falls back to Image.file(input.file). Re-rendered after each tool apply.
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
source → Image?
Decoded source image. Null until ensureSource completes.
no setter
sourceId → Object?
Picker-side identity used to look up the bubble's GallerySource for the open / close hero-flight. Null for camera / file-pick flows that have no on-screen source to fly from / to — those fall back to the no-transition path.
final
sourceSize → Size?
Source bitmap dims, once decoded; null until the first tool is opened (or ensureSourceForTest is called).
no setter
videoController ↔ XVideoPlayerController?
Player of a video entry's preview; absent for other media, before ensureVideoInitialized and after the last releaseVideo.
getter/setter pair
videoEdit ↔ VideoEditValues
Per-entry trim / mute state (V1 of the video-editing plan; telegram's videoTrimRange / videoIsMuted). Survives tool re-entries like the crop/draw layers; travels to the send pipeline via ComposeResult.videoEdit.
getter/setter pair
viewerController → TransformationController
Pinch-zoom transform of the preview.
latefinal

Methods

addDispose(VoidCallback callback) → void
Registers a disposal callback. Ignored if already disposed.
inherited
addListener(VoidCallback listener) → void
Register a closure to be called when the object notifies its listeners.
inherited
bakeViewerTransform() → void
Compose the user's compose-page pan/zoom (held by viewerController from the InteractiveViewer) into camera and reset the viewer to identity. Called by ComposePage._openTool so the tool screen's cameraAnimator starts from what the user is currently looking at — pre-fix the camera was still at the original fit and the image visibly snapped back when crop / draw mounted.
captureImage() → Future<Image?>
The final image for avatar-style callers, as a handle the caller disposes. Unlike composedImage, this also yields an unedited source image so the avatar matches the preview instead of any raw file metadata quirks. Null for a video or an image that cannot be decoded.
composedImage() → Future<Image?>
In-memory composite for the send pipeline. Returns the cached renderedPreview when available (the common case — tool applies eagerly rasterise into it); otherwise waits for the render of the current edits. Null when there are no edits — callers upload input as-is.
dispose() → void
Releases whatever this object holds. Calling it twice is an error.
override
disposeBy(Dispose disposer) → void

Available on Disposable, provided by the DisposableDisposerExtension extension

Adds this object's dispose to another Dispose collector.
ensureSource() → Future<Image?>
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.
ensureSourceForTest() → Future<Image?>
Test hook: eagerly decode input.file and cache it as source.
ensureVideoInitialized() → Future<void>
Lazily initialise the video controller and start looping playback. Safe to call multiple times — only the first invocation kicks off the load.
ensureVideoPosterForTest() → Future<Image?>
Test hook: decode the video crop poster exactly like openCropEditor does (native resolution, cached as source).
handOverVideoEdit() → VideoEditValues?
videoEdit for a submitted ComposeResult, absent without edits. Its overlay's file passes to the caller, which deletes it once used.
invalidatePreviewForTest() → void
Test hook: dispose and clear renderedPreview. Tests call this before a second refreshPreviewForTest so the new render is a distinct image (and the old one's GPU bitmap is released).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Notifies all registered listeners.
inherited
openCropEditor() → Future<void>
Open the crop tool. Images crop their decoded source; videos crop a poster frame extracted at videoEdit's trim start (telegram's model — the same CropImageLayer geometry drives the export). The crop layer is borrowed by CropScreen.borrowed; its state survives back on this entry. On apply, an image re-renders its preview while a video snapshots the layer geometry into videoEdit.crop (the live player preview + send-time export read it); cancels restore the layer from its snapshot (taken on tool-open).
openDrawEditor() → Future<void>
Opens the draw tool over the decoded image or the video's poster frame.
pauseVideo() → void
Pauses the video preview.
refitCamera({Curve? curve, Duration? duration}) → void
Re-target the camera at the current fit rect + crop rect without changing either — the crop editor calls this after a handle-drag confirm / aspect snap so the (new) crop rect refills the surface. curve/duration select the animation feel (TgSpring for the telegram evenlyFill confirm).
refreshPreviewForTest() → Future<void>
Test hook: force a preview re-render. Production code reaches _renderPreview indirectly via tool apply; tests need to call it after directly mutating cropLayer / drawLayer.
release() → void
Drops a hold; the last one disposes this entry.
releaseVideo() → Future<void>
Drops a hold on videoController; the last one disposes it, so the looping video and its audio stop once no screen shows the entry, and the next retainVideo loads a fresh player.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that the object notifies.
inherited
resumeVideo() → void
Plays the video preview.
retain() → void
Holds this entry alive until a matching release.
retainVideo() → Future<void>
Holds videoController until a matching releaseVideo, loading it for the first hold.
setFitRect(Rect next) → void
Update the rect into which the image should fit. Snaps the camera on the first call (rect previously zero / source not yet decoded), animates otherwise. Re-entrant: a same-rect call short-circuits.
setVideoEdit(VideoEditValues next) → void
Scrubber/mute write path: stores the values, applies volume immediately, and snaps the playhead into the trim range.
snapshotDrawOverlayForTest() → Future<void>
Test hook: bake strokes and text entities into videoEdit.overlay exactly like a draw-tool apply does.
subscribe(VoidCallback callback) → VoidCallback

Available on Listenable, provided by the ListenableExtension extension

Adds callback as listener and returns a function to remove it.
toString() → String
A string representation of this object.
inherited

Operators

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

Static Methods

cropGeometryFrom(CropImageLayer layer) → VideoCropGeometry
Snapshot the crop layer's source→output geometry into a VideoCropGeometry — the export affine (row-major 3×3 from exportMatrix, whose column-major storage we index by entry) plus the crop output size. Dimensions are raw here; the send path clamps them to the quality tier.