79728461

Date: 2025-08-07 11:11:00
Score: 0.5
Natty:
Report link

When a container is un-selected the outer Focus widget sets canRequestFocus = false and skipTraversal = faslse on every descendant focus-node.

Because the TextField inside _SearchField owns its own persistent FocusNode, that flag stays false even after the container becomes selected again, so the Tab key can never land on that field any more – only on the button (which creates a brand-new internal focus-node each rebuild).

So the properties need to be updated once the container is selected again inside didUpdateWidget method and pass the isContainerSelected flag to the _SearchField widget from parent.

class _SearchFieldState extends State<_SearchField> {
  final FocusNode _focusNode = FocusNode();

  @override
  void didUpdateWidget(final _SearchField oldWidget) {
    super.didUpdateWidget(oldWidget);
    if (oldWidget.isSectionSelected != widget.isContainerSelected) {
      _focusNode
        ..canRequestFocus = widget.isContainerSelected
        ..skipTraversal = !widget.isContainerSelected;
    }
  }

  @override
  void dispose() {
    _focusNode.dispose();
    super.dispose();
  }

  @override
  Widget build(final BuildContext context) {
    return TextField(
      focusNode: _focusNode,
      decoration: const InputDecoration(
        hintText: 'Search',
      ),
    );
  }
}
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Starts with a question (0.5): When a
  • Low reputation (1):
Posted by: Sumit