I suppose you are looking for FocusNode
.
To listen to focus change, you can add a listner to the FocusNode
and specify the focusNode
to TextField
.
Example:
class TextFieldFocus extends StatefulWidget {
@override
_TextFieldFocusState createState() => new _TextFieldFocusState();
}
class _TextFieldFocusState extends State<TextFieldFocus> {
FocusNode _focus = new FocusNode();
TextEditingController _controller = new TextEditingController();
@override
void initState() {
super.initState();
_focus.addListener(_onFocusChange);
}
void _onFocusChange(){
debugPrint("Focus: "+_focus.hasFocus.toString());
}
@override
Widget build(BuildContext context) {
return new Container(
color: Colors.white,
child: new TextField(
focusNode: _focus,
),
);
}
}
This gist represents how to ensure a focused node to be visible on the ui.
Hope it helps!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…