Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to listen focus change in flutter?

In Android, we can call setOnFocusChangeListener(), do something in onFocusChanged() method, but flutter does not provider onFocus() interface like onTap() in GestureDetector or onKey() in RawKeyboardListener.

I have read flutter api about focus, https://docs.flutter.io/flutter/widgets/FocusManager-class.html but I can't find a way to realize my request, anyone who can give me a hand?

like image 687
coder.john Avatar asked Dec 25 '17 01:12

coder.john


People also ask

What is autofocus Flutter?

autofocus property Null safety bool autofocus. Whether this text field should focus itself if nothing else is already focused. If true, the keyboard will open as soon as this text field obtains focus. Otherwise, the keyboard is only shown after the user taps the text field.


1 Answers

In addtion you can use Focus widget.

Focus(   child: TextFormField(...),   onFocusChange: (hasFocus) {     if(hasFocus) {       // do stuff     }   }, ) 
like image 84
BambinoUA Avatar answered Sep 19 '22 01:09

BambinoUA