Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.8.1

* fixed [#95](https://github.com/flutter/ai/issues/95): Image Attachment
Disappears After Audio Recording

## 0.8.0
* fixed [#90](https://github.com/flutter/ai/issues/90): Input box
shrinks unexpectedly when clicking file attachment button – customization not
Expand Down
10 changes: 6 additions & 4 deletions lib/src/views/chat_input/chat_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ class ChatInput extends StatefulWidget {

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

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

// will come back as initialMessage
widget.onTranslateStt(file);
// Pass current attachments to onTranslateStt
widget.onTranslateStt(file, List.from(_attachments));
}

void onAttachments(Iterable<Attachment> attachments) {
Expand Down
13 changes: 10 additions & 3 deletions lib/src/views/llm_chat_view/llm_chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ class _LlmChatViewState extends State<LlmChatView>
});
}

Future<void> _onTranslateStt(XFile file) async {
Future<void> _onTranslateStt(
XFile file,
Iterable<Attachment> currentAttachments,
) async {
assert(widget.enableVoiceNotes);
_initialMessage = null;
_associatedResponse = null;
Expand All @@ -297,7 +300,9 @@ class _LlmChatViewState extends State<LlmChatView>
attachments: attachments,
),
onUpdate: (text) => response += text,
onDone: (error) async => _onSttDone(error, response, file),
onDone:
(error) async =>
_onSttDone(error, response, file, currentAttachments),
);

setState(() {});
Expand All @@ -307,10 +312,12 @@ class _LlmChatViewState extends State<LlmChatView>
LlmException? error,
String response,
XFile file,
Iterable<Attachment> attachments,
) async {
assert(_pendingSttResponse != null);
setState(() {
_initialMessage = ChatMessage.user(response, []);
// Preserve any existing attachments from the current input
_initialMessage = ChatMessage.user(response, attachments);
_pendingSttResponse = null;
});

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: flutter_ai_toolkit
description: >-
A set of AI chat-related widgets for Flutter apps targeting
mobile, desktop, and web.
version: 0.8.0
version: 0.8.1
repository: https://github.com/flutter/ai

topics:
Expand Down