Skip to content

Commit 600e682

Browse files
authored
fix #95: Image Attachment Disappears After Audio Recording (#104)
1 parent a96a0fe commit 600e682

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.8.1
2+
3+
* fixed [#95](https://github.com/flutter/ai/issues/95): Image Attachment
4+
Disappears After Audio Recording
5+
16
## 0.8.0
27
* fixed [#90](https://github.com/flutter/ai/issues/90): Input box
38
shrinks unexpectedly when clicking file attachment button – customization not

lib/src/views/chat_input/chat_input.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ class ChatInput extends StatefulWidget {
5757

5858
/// Callback function triggered when speech-to-text translation is requested.
5959
///
60-
/// Takes an [XFile] representing the audio file to be translated.
61-
final void Function(XFile file) onTranslateStt;
60+
/// Takes an [XFile] representing the audio file to be translated and the
61+
/// current attachments.
62+
final void Function(XFile file, Iterable<Attachment> attachments)
63+
onTranslateStt;
6264

6365
/// The initial message to populate the input field, if any.
6466
final ChatMessage? initialMessage;
@@ -249,8 +251,8 @@ class _ChatInputState extends State<ChatInput> {
249251
return;
250252
}
251253

252-
// will come back as initialMessage
253-
widget.onTranslateStt(file);
254+
// Pass current attachments to onTranslateStt
255+
widget.onTranslateStt(file, List.from(_attachments));
254256
}
255257

256258
void onAttachments(Iterable<Attachment> attachments) {

lib/src/views/llm_chat_view/llm_chat_view.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ class _LlmChatViewState extends State<LlmChatView>
277277
});
278278
}
279279

280-
Future<void> _onTranslateStt(XFile file) async {
280+
Future<void> _onTranslateStt(
281+
XFile file,
282+
Iterable<Attachment> currentAttachments,
283+
) async {
281284
assert(widget.enableVoiceNotes);
282285
_initialMessage = null;
283286
_associatedResponse = null;
@@ -297,7 +300,9 @@ class _LlmChatViewState extends State<LlmChatView>
297300
attachments: attachments,
298301
),
299302
onUpdate: (text) => response += text,
300-
onDone: (error) async => _onSttDone(error, response, file),
303+
onDone:
304+
(error) async =>
305+
_onSttDone(error, response, file, currentAttachments),
301306
);
302307

303308
setState(() {});
@@ -307,10 +312,12 @@ class _LlmChatViewState extends State<LlmChatView>
307312
LlmException? error,
308313
String response,
309314
XFile file,
315+
Iterable<Attachment> attachments,
310316
) async {
311317
assert(_pendingSttResponse != null);
312318
setState(() {
313-
_initialMessage = ChatMessage.user(response, []);
319+
// Preserve any existing attachments from the current input
320+
_initialMessage = ChatMessage.user(response, attachments);
314321
_pendingSttResponse = null;
315322
});
316323

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: flutter_ai_toolkit
22
description: >-
33
A set of AI chat-related widgets for Flutter apps targeting
44
mobile, desktop, and web.
5-
version: 0.8.0
5+
version: 0.8.1
66
repository: https://github.com/flutter/ai
77

88
topics:

0 commit comments

Comments
 (0)