diff --git a/lib/src/models/config_models/send_message_configuration.dart b/lib/src/models/config_models/send_message_configuration.dart index 8909d7a3..39fa8c35 100644 --- a/lib/src/models/config_models/send_message_configuration.dart +++ b/lib/src/models/config_models/send_message_configuration.dart @@ -41,6 +41,9 @@ class SendMessageConfiguration { /// Used to give reply dialog color. final Color? replyDialogColor; + /// Provides call when user add action on submit and enter is pressed. + final StringCallback? onSubmitted; + /// Used to give color to title of reply pop-up. final Color? replyTitleColor; @@ -87,6 +90,7 @@ class SendMessageConfiguration { this.replyDialogColor, this.replyTitleColor, this.replyMessageColor, + this.onSubmitted, this.closeIconColor, this.allowRecordingVoice = true, this.enableCameraImagePicker = true, @@ -137,6 +141,9 @@ class TextFieldConfiguration { /// Used to give text style of hint text in text field. final TextStyle? hintStyle; + /// Used to text input action from keyboard enter button. + final TextInputAction textInputAction; + /// Used to give text style of actual text in text field. final TextStyle? textStyle; @@ -183,6 +190,7 @@ class TextFieldConfiguration { this.compositionThresholdTime = const Duration(seconds: 1), this.inputFormatters, this.textCapitalization, + this.textInputAction = TextInputAction.newline, this.enabled = true, }); } diff --git a/lib/src/widgets/chatui_textfield.dart b/lib/src/widgets/chatui_textfield.dart index ec6cf0bc..90ced717 100644 --- a/lib/src/widgets/chatui_textfield.dart +++ b/lib/src/widgets/chatui_textfield.dart @@ -26,6 +26,7 @@ import 'package:audio_waveforms/audio_waveforms.dart'; import 'package:chatview/src/utils/constants/constants.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:image_picker/image_picker.dart'; import '../../chatview.dart'; @@ -182,6 +183,14 @@ class _ChatUITextFieldState extends State { keyboardType: textFieldConfig?.textInputType, inputFormatters: textFieldConfig?.inputFormatters, onChanged: _onChanged, + onSubmitted: (inputText) { + if (sendMessageConfig?.onSubmitted != null) { + sendMessageConfig!.onSubmitted!(inputText); + } else { + _onSubmitted(inputText); + } + }, + textInputAction:textFieldConfig?.textInputAction ?? TextInputAction.newline, enabled: textFieldConfig?.enabled, textCapitalization: textFieldConfig?.textCapitalization ?? TextCapitalization.sentences, @@ -373,6 +382,28 @@ class _ChatUITextFieldState extends State { } } + bool _isWebOrDesktop() { + return kIsWeb || Platform.isMacOS || Platform.isWindows || Platform.isLinux; + } + + void _onSubmitted(String inputText){ + bool isShiftPressed = HardwareKeyboard.instance.isShiftPressed; + if(_isWebOrDesktop() && isShiftPressed){ + widget.textEditingController.text += '\n'; + WidgetsBinding.instance.addPostFrameCallback((_) { + widget.textEditingController.selection = TextSelection.fromPosition( + TextPosition(offset: widget.textEditingController.text.length), + ); + widget.focusNode.requestFocus(); + }); + }else{ + if(inputText.isNotEmpty){ + widget.onPressed(); + _inputText.value = ''; + } + } + } + void _onChanged(String inputText) { debouncer.run(() { composingStatus.value = TypeWriterStatus.typed;