Text and attachments can reach the server at different times. Model that difference so a message can remain understandable without claiming its files are available before they are linked and accessible.
Define whether a message may be delivered with pending attachments or must wait for all required content. The correct choice follows the task, not whichever request happens to finish first.
Give the message and each file stable identity
Keep one logical message reference and separate attachment references with ownership, local file, upload state, and remote linkage. Preserve the relationship through retries and process restarts.
Avoid using a temporary filename as the only connection between text and file. Repeated names, cleanup, and replacement can otherwise attach the wrong object or make recovery ambiguous.
Test a fictional field-team message
Suppose a technician sends “Leak location shown in photos” with two images while connectivity is weak. The text succeeds, one image uploads, and the other fails. The recipient should see the actual content state under the chosen product policy.
If the message is usable with partial files, show an honest pending or unavailable attachment state. If the images are required for the business decision, avoid presenting the message as fully delivered. Give the sender a scoped retry or correction path.
Test attachment completion before text acceptance, text rejection after file storage, deleted message, cancellation, missing local image, and duplicate completion notification. Inspect recipient views, server links, local queue, and orphaned objects.
Keep ordering and cleanup coherent
A file may need the message's server identity before linking, while transfer can sometimes begin independently. Express that dependency explicitly and define what happens if the parent is never accepted.
Deletion and account changes need the same review. Removing message text should not leave an unintended accessible file, and a new account should not inherit the previous user's pending attachments.
The tradeoff is faster partial communication versus simpler completion semantics. Sending text first can help conversation flow, but creates recipient states and cleanup work. Waiting for every file can simplify meaning while increasing delay and the risk that users assume nothing was sent.
Flutter's offline-first guide gives architectural context. The Social App case study documents related messaging and native offline work. This leak-location message is fictional and does not describe its internal protocol.
Questions about separate attachment sync
Does text acceptance mean the whole message is delivered?
Only if that is the defined contract and all required content is available. Otherwise, show separate status clearly.
Should failed files force text to resend?
Not automatically. Retry the affected logical attachment under the duplicate policy and preserve the parent relationship.
What should be tested first?
Accept text, fail one file, restart the app, and inspect both sender and recipient states. Bring misleading completion or orphaned files to a messaging-data review.