Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter TextField FocusNode not gaining focus back [FocusNode "NOT FOCUSABLE"]

Tags:

flutter

dart

I have a TextField with a focusNode that suddenly stops gaining focus after changing screens. One thing I notice though, the object changes its value canRequestFocus to false for no reason.

FocusNode value before launching other Widget:

FocusNode#1502a(context: EditableText-[LabeledGlobalKey<EditableTextState>#26e29])

FocusNode value after launching other Widget and TextField doesn't get focus when I tap:

FocusNode#1502a(context: EditableText-[LabeledGlobalKey<EditableTextState>#26e29], NOT FOCUSABLE)

The problem doesn't happen on Android.

I've created this Sample Project and this Video showing how to reproduce the issue.

like image 541
Renan Nery Avatar asked Nov 21 '25 15:11

Renan Nery


1 Answers

I encountered the same issue today, with Flutter version 3.22.1. My solution was to use a custom subclass of FocusNode to create the focus node:

class _FocusNode extends FocusNode {
  @override
  bool get canRequestFocus => true;
}

This overrides the problematic variable, and makes the text field always focusable.

like image 54
tutti Avatar answered Nov 23 '25 06:11

tutti