Fix send on enter on mobile

This commit is contained in:
Henry Hiles 2026-03-24 16:14:42 -04:00
commit e5062683e8
No known key found for this signature in database

View file

@ -1,4 +1,3 @@
import "dart:io";
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter/services.dart"; import "package:flutter/services.dart";
import "package:flutter_chat_core/flutter_chat_core.dart"; import "package:flutter_chat_core/flutter_chat_core.dart";
@ -55,16 +54,11 @@ class ChatBox extends HookConsumerWidget {
final node = useFocusNode( final node = useFocusNode(
onKeyEvent: (_, event) { onKeyEvent: (_, event) {
if (event is KeyDownEvent && !Platform.isAndroid && !Platform.isIOS) { if (event is KeyDownEvent &&
if (event.logicalKey == LogicalKeyboardKey.enter && event.logicalKey == LogicalKeyboardKey.escape) {
!HardwareKeyboard.instance.isShiftPressed) {
send();
return KeyEventResult.handled;
} else if (event.logicalKey == LogicalKeyboardKey.escape) {
onDismiss(); onDismiss();
return KeyEventResult.handled; return KeyEventResult.handled;
} }
}
return KeyEventResult.ignored; return KeyEventResult.ignored;
}, },
@ -156,6 +150,9 @@ class ChatBox extends HookConsumerWidget {
), ),
controller: controller.value, controller: controller.value,
key: key, key: key,
// TODO: Setting for send on enter on / off
onFieldSubmitted: (_) => send(),
textInputAction: TextInputAction.done,
focusNode: node, focusNode: node,
), ),
), ),