Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter : how to use focusNode property on TextField

Tags:

flutter

dart

I want to control the TextField widget when f user taps on it. How can I implement the focusNode property? There's no detailed explanation in the description.

like image 457
Ahmad Jamil Al Rasyid Avatar asked Sep 03 '25 03:09

Ahmad Jamil Al Rasyid


1 Answers

FocusNode focusNode;

void initState() {
  focusNode = new FocusNode();

  // listen to focus changes
  focusNode.addListener(() => print('focusNode updated: hasFocus: ${focusNode.hasFocus}')); 
}

void setFocus() {
  FocusScope.of(context).requestFocus(focusNode);
}

Widget build() {
  return
  ...
  new TextField(focusNode: focusNode, ...);
}
like image 65
Günter Zöchbauer Avatar answered Sep 07 '25 20:09

Günter Zöchbauer