fix: return focus to message input after sending
Added FocusNode to TextField, requestFocus() after send completes. Also autofocus=true so cursor is in the input when entering a room. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -52,6 +52,7 @@ class MessageInput extends StatefulWidget {
|
|||||||
|
|
||||||
class _MessageInputState extends State<MessageInput> {
|
class _MessageInputState extends State<MessageInput> {
|
||||||
final _controller = TextEditingController();
|
final _controller = TextEditingController();
|
||||||
|
final _focusNode = FocusNode();
|
||||||
bool _hasText = false;
|
bool _hasText = false;
|
||||||
bool _isPickingFile = false;
|
bool _isPickingFile = false;
|
||||||
|
|
||||||
@@ -67,6 +68,7 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_controller.dispose();
|
_controller.dispose();
|
||||||
|
_focusNode.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +77,8 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
if (text.isEmpty) return;
|
if (text.isEmpty) return;
|
||||||
_controller.clear();
|
_controller.clear();
|
||||||
await widget.onSend(text);
|
await widget.onSend(text);
|
||||||
|
// Return focus to the input so the user can keep typing.
|
||||||
|
_focusNode.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _pickFile() async {
|
Future<void> _pickFile() async {
|
||||||
@@ -180,6 +184,8 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
|
focusNode: _focusNode,
|
||||||
|
autofocus: true,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
hintText: 'Message',
|
hintText: 'Message',
|
||||||
contentPadding: EdgeInsets.symmetric(
|
contentPadding: EdgeInsets.symmetric(
|
||||||
|
|||||||
Reference in New Issue
Block a user