feat: submit the chat message inputfield when enter is pressed

This commit is contained in:
Freek van de Ven 2025-02-17 15:14:39 +01:00 committed by FlutterJoey
parent 7a0fd49070
commit 02ae851d13
3 changed files with 6 additions and 0 deletions

View file

@ -14,6 +14,7 @@
- Added loadNewMessagesAfter, loadOldMessagesBefore and removed pagination from getMessages in the ChatRepositoryInterface to change pagination behavior to rely on the stream and two methods indicating that more messages should be added to the stream
- Added chatTitleResolver that can be used to resolve the chat title from the chat model or return null to allow for default behavior
- Added ChatPaginationControls to the ChatOptions to allow for more control over the pagination
- Fixed that chat message is automatically sent when the user presses enter on the keyboard in the chat input
## 4.0.0
- Move to the new user story architecture

View file

@ -106,6 +106,7 @@ typedef TextInputBuilder = Widget Function(
TextEditingController textEditingController,
Widget suffixIcon,
ChatTranslations translations,
VoidCallback onSubmit,
);
/// The base screen builder

View file

@ -77,6 +77,8 @@ class ChatBottomInputSection extends HookWidget {
],
);
Future<void> onSubmitField() async => sendMessage();
var defaultInputField = TextField(
textAlign: TextAlign.start,
textAlignVertical: TextAlignVertical.center,
@ -106,6 +108,7 @@ class ChatBottomInputSection extends HookWidget {
),
suffixIcon: messageSendButtons,
),
onSubmitted: (_) async => onSubmitField(),
);
return Padding(
@ -117,6 +120,7 @@ class ChatBottomInputSection extends HookWidget {
textController,
messageSendButtons,
options.translations,
onSubmitField,
) ??
defaultInputField,
),