How to show the Keyboard automatically for a Textfield in Flutter
You can use the autofocus:true
property of the TextField:
Whether this text field should focus itself if nothing else is already focused.
So whenever the widget appears on screen, if theres nothing else with the keyboard focus, the focus will automatically be directed to it, thus opening the keyboard.
TextField(TextEditingController: controller,
focusNode: focusNode,
autofocus:true)
You can set the autofocus property on TextField to true:
TextField(
autofocus: true,
);
Hope it helps!
class yourWidget extends StatelessWidget {
FocusNode inputNode = FocusNode();
// to open keyboard call this function;
void openKeyboard(){
FocusScope.of(context).requestFocus(inputNode)
}
@override
Widget build(BuildContext context) {
TextFormField(
//assign the node like this
focusNode: inputNode,
autofocus:true,)
}