Home > Software design >  Make cursor automatically enter textfield in alertdialog in flutter
Make cursor automatically enter textfield in alertdialog in flutter

Time:04-21

I am trying to make an alertdialog with a textfield and a button. Would like it if each time the alertdialog is called, the textcursor will automatically go into the textfield. Is it possible to do this in flutter?

CodePudding user response:

TextField(
   autofocus: true,
)

some extra tip to programmatically focus on textfield

FocusNode myFocusNode = FocusNode();
TextField(
   focusNode: myFocusNode,
)

in where you want to specifically focus the textfield

FocusScope.of(context).requestFocus(myFocusNode);
  • Related