2

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:

enter image description here

The focus is on first field text (email). But on soft keyboard not show Next button (green button). Show Done button. Why?

Alexei
  • 14,350
  • 37
  • 121
  • 240

3 Answers3

2

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

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
2

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

Vinoth Vino
  • 9,166
  • 3
  • 66
  • 70
0

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?

Adelina
  • 10,915
  • 1
  • 38
  • 46