From a9c562653fe9ac9bdf25322d258614d14d05ed25 Mon Sep 17 00:00:00 2001 From: Divyanshu Bhargava Date: Thu, 8 Oct 2026 02:13:20 +0530 Subject: [PATCH] fix: keep the composer's focus when the chat view leaves its zero state --- packages/flow_ui/CHANGELOG.md | 1 + packages/flow_ui/lib/src/widgets/flow_chat_view.dart | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/flow_ui/CHANGELOG.md b/packages/flow_ui/CHANGELOG.md index 7ad47ea..86f3683 100644 --- a/packages/flow_ui/CHANGELOG.md +++ b/packages/flow_ui/CHANGELOG.md @@ -10,6 +10,7 @@ - Adds FlowComposer.sendTooltip and stopTooltip, host-localized names for the send and stop buttons. Both now read as buttons with their enabled state, so a disabled send button no longer drops out of the accessibility tree. - Fixes Enter sending the draft while an input method is still composing: Enter now confirms the composition, as in any text field. - Enter no longer adds a newline while a reply streams, or when held down after a send; Shift+Enter still inserts one. +- Keeps the composer's focus when FlowChatView leaves its wide zero state. The view rebuilt the composer as it moved from the centre to the bottom edge, so the field lost focus on the first send; it now moves the same composer, state and all. ## 0.3.0 diff --git a/packages/flow_ui/lib/src/widgets/flow_chat_view.dart b/packages/flow_ui/lib/src/widgets/flow_chat_view.dart index 2ce6f5c..5ff2c14 100644 --- a/packages/flow_ui/lib/src/widgets/flow_chat_view.dart +++ b/packages/flow_ui/lib/src/widgets/flow_chat_view.dart @@ -286,6 +286,7 @@ class _FlowChatViewState extends State { static const double _suggestionsGapCompact = 16; static const double _suggestionsExtraInset = 8; + final GlobalKey _composerKey = GlobalKey(); bool _showJump = false; Timer? _jumpDebounce; @@ -634,7 +635,7 @@ class _FlowChatViewState extends State { if (widget.aboveComposer != null) widget.aboveComposer!, if (widget.composer != null) ...[ if (widget.aboveComposer != null) const SizedBox(height: _composerGap), - widget.composer!, + KeyedSubtree(key: _composerKey, child: widget.composer!), ], ]; @@ -722,7 +723,7 @@ class _FlowChatViewState extends State { } else if (column.isNotEmpty) { column.add(const SizedBox(height: _suggestionsGapCompact)); } - column.add(widget.composer!); + column.add(KeyedSubtree(key: _composerKey, child: widget.composer!)); } return [