@@ -26,6 +26,7 @@ import 'package:audio_waveforms/audio_waveforms.dart';
26
26
import 'package:chatview/src/utils/constants/constants.dart' ;
27
27
import 'package:flutter/foundation.dart' ;
28
28
import 'package:flutter/material.dart' ;
29
+ import 'package:flutter/services.dart' ;
29
30
import 'package:image_picker/image_picker.dart' ;
30
31
31
32
import '../../chatview.dart' ;
@@ -182,6 +183,14 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
182
183
keyboardType: textFieldConfig? .textInputType,
183
184
inputFormatters: textFieldConfig? .inputFormatters,
184
185
onChanged: _onChanged,
186
+ onSubmitted: (inputText) {
187
+ if (sendMessageConfig? .onSubmitted != null ) {
188
+ sendMessageConfig! .onSubmitted !(inputText);
189
+ } else {
190
+ _onSubmitted (inputText);
191
+ }
192
+ },
193
+ textInputAction: textFieldConfig? .textInputAction ?? TextInputAction .newline,
185
194
enabled: textFieldConfig? .enabled,
186
195
textCapitalization: textFieldConfig? .textCapitalization ??
187
196
TextCapitalization .sentences,
@@ -373,6 +382,28 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
373
382
}
374
383
}
375
384
385
+ bool _isWebOrDesktop () {
386
+ return kIsWeb || Platform .isMacOS || Platform .isWindows || Platform .isLinux;
387
+ }
388
+
389
+ void _onSubmitted (String inputText){
390
+ bool isShiftPressed = HardwareKeyboard .instance.isShiftPressed;
391
+ if (_isWebOrDesktop () && isShiftPressed){
392
+ widget.textEditingController.text += '\n ' ;
393
+ WidgetsBinding .instance.addPostFrameCallback ((_) {
394
+ widget.textEditingController.selection = TextSelection .fromPosition (
395
+ TextPosition (offset: widget.textEditingController.text.length),
396
+ );
397
+ widget.focusNode.requestFocus ();
398
+ });
399
+ }else {
400
+ if (inputText.isNotEmpty){
401
+ widget.onPressed ();
402
+ _inputText.value = '' ;
403
+ }
404
+ }
405
+ }
406
+
376
407
void _onChanged (String inputText) {
377
408
debouncer.run (() {
378
409
composingStatus.value = TypeWriterStatus .typed;
0 commit comments