Reputation: 15664
android studio 3.6
@override
Widget build(BuildContext context) {
logger.d("build:");
//String _errorMessage = null;
return Scaffold(
key: _scaffoldKey,
appBar: new AppBar(
centerTitle: true,
title: new Text('Sign in',
style: TextStyle(fontWeight: FontWeight.bold))),
body: new Container(
margin: const EdgeInsets.only(
left: Constants.DEFAULT_MARGIN,
right: Constants.DEFAULT_MARGIN),
child: new Form(
key: _formKey,
child: new Column(children: [
new TextFormField(
decoration: new InputDecoration(hintText: 'Email'),
keyboardType: TextInputType.emailAddress,
onChanged: (value) {
setState(() {
_email = value;
});
}),
new TextFormField(
decoration: new InputDecoration(hintText: 'Password'),
obscureText: true,
onChanged: (value) {
setState(() {
_password = value;
});
})
]))));
}
Here result:
The focus is on first field text (email). But on soft keyboard not show Next button (green button). Show Done button. Why?
Upvotes: 2
Views: 1183
Reputation: 9734
Just add textInputAction
property and assign TextInputAction.next
enum to it. This will display the next button on the keyboard. FocusScope will allow you to change the keyboard focus. Here I just used nextFocus() to change the keyboard focus to the next TextFormField when pressing the next button.
TextFormField(
...
textInputAction: TextInputAction.next,
onFieldSubmitted: (value){
FocusScope.of(context).nextFocus();
}
...
)
For more textInputAction
types, please have a look at this TextInputAction documentation
Upvotes: 2
Reputation: 11891
If you wanna see next button in the keyboard should
TextFormField(
...
textInputAction: TextInputAction.next,
...
)
But this alone will not focus on next input field.
Please check: https://medium.com/flutterpub/flutter-keyboard-actions-and-next-focus-field-3260dc4c694 or How to shift focus to next textfield in flutter?
Upvotes: 0
Reputation: 107131
You need to specify the textInputAction
property to get that behaviour.
TextFormField(
decoration: new InputDecoration(hintText: 'Email'),
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
onChanged: (value) {
setState(() {
_email = value;
});
}
)
Refer TextInputAction for all the available types
Upvotes: 2