AI Agent Component Spec
AI Agent Component Spec
- When a user picks an image, an inline preview appears above the composer. They can type a caption, then tap send — or cancel to discard.
- Image messages that include a caption display the caption text below the thumbnail in the message bubble.
Components
Architecture
Integration Steps
1. Add State for Pending Image
Track the pending image path and a reference to the composer controller in your messages screen state.2. Create the Inline Image Preview Widget
This widget renders a thumbnail and cancel button above the composer. It usesFileUtils.normalizeFilePath() to handle percent-encoded iOS file paths.
File: image_preview_screen.dart
3. Build Custom Attachment Options
Replace the default image/camera attachment options with versions that pick the file but show a preview instead of sending immediately. Non-image options (video, audio, file) have noonItemClick, so they fall through to the default pick-and-send behavior.
4. Show and Clear the Preview Panel
When an image is picked, store the path and inject a zero-width space (\u200B) into the text field to enable the send button. On cancel, clear the state and remove the placeholder only if no real text was typed.
5. Intercept the Send Button
When the user taps send with a pending image, build aMediaMessage with the caption and send it via CometChatUIKit.sendMediaMessage(). Otherwise, forward to the default SDK send.
The caption is read from the TextMessage object passed to the callback — not from the text field — because the controller clears the text field before calling onSendButtonTap.
6. Wire Up the Composer
Pass all four extension points toCometChatCompactMessageComposer:
7. Render Captions in Image Bubbles
Create a customCometChatMessageTemplate for image messages that wraps the default image bubble with a caption Text widget below it.
CometChat stores the caption in MediaMessage.caption and also in metadata['text']. The template checks both locations.
8. Apply the Custom Template to the Message List
Use thetemplates parameter on CometChatMessageList to replace the default image template. Filter out the built-in image template and append the custom one.
Key Gotchas
Feature Matrix
Next Steps
Compact Message Composer
Full reference for the compact composer component.
Message Template
Customize how message types are rendered.
Message List
Configure the message list component.
All Guides
Browse all feature and formatter guides.