handleSubmit method
Walk each entry and capture (a) the original picker media,
(b) the in-memory composited image for edited entries, then
invoke onSubmit before pop so the chat bubbles exist by
the time the close hero captures its destination. Mirrors
telegram's completion(results, finishedCallback) order:
insert first, then animateOut(finished: true).
Implementation
Future<void> handleSubmit() async {
if (_completed) return;
_completed = true;
_submitStarted = true;
_completedReset?.cancel();
_completedReset = Chrono(const Duration(milliseconds: 1500), () {
_completed = false;
});
final results = <ComposeResult>[];
for (final e in entries) {
final composed = await e.composedImage();
results.add(
ComposeResult(
source: e.input,
composedImage: composed,
caption: _showsCaption
? MediaHost.current.caption(e.composerController)
: null,
videoEdit: e.handOverVideoEdit(),
imageBytes: purpose == ComposePurpose.avatar
? (_avatarBytes(e.input, await e.captureImage(), maxImageExtent)
..ignore())
: null,
),
);
}
final submit = onSubmit;
_submitted = await submit?.call(results);
// Repoint the hide slot at the just-mounted chat bubble so it
// stays invisible behind the close morph; the snapshot lands on
// an empty rect and the bubble unhides when compose is removed.
_syncHideSlot();
// The inserted bubble registers its source during the next build.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (disposed) return;
pop(results);
});
// onSubmit normally dirties the chat tree (placeholder bubble mounts),
// which schedules the frame the post-frame callback runs after. When
// onSubmit is null or a no-op, nothing else requests a frame — make
// sure one is scheduled so the pop is reachable.
WidgetsBinding.instance.scheduleFrame();
}