TextInputAction.next Makes the Keyboard Dissapear

Viewed 186

I am using TextFormField in my Flutter app, like in this snippet:

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Column(
      children: <Widget>[
        TextField(
          decoration: InputDecoration(hintText: "TextField A"),
          textInputAction: TextInputAction.next,
          onSubmitted: (_) => FocusScope.of(context).nextFocus(), // move focus to next
        ),
        TextField(
          decoration: InputDecoration(hintText: "TextField B"),
          textInputAction: TextInputAction.next,
          onSubmitted: (_) => FocusScope.of(context).nextFocus(), // move focus to next
        ),
        TextField(
          decoration: InputDecoration(hintText: "TextField C"),
          textInputAction: TextInputAction.done,
          onSubmitted: (_) => FocusScope.of(context).unfocus(), // submit and hide keyboard
        ),
      ],
    ),
  );
}

My problem is that whenever the next field is behind the keyboard, the keyboard just disappears instead of moving to the next focus...

This is a video of the problem:

https://www.youtube.com/watch?v=h-Cv2UpnHrY&feature=youtu.be

As you can see, my wanted behaviour is the focus to move from the email field to the address field, but instead the keyboard disappears and nothing happens.

How can I solve it?

1 Answers

I think you have to create a new object first of all that is..I am using another example just to demonstrate:

 final FocusNode _emailFocusNode = FocusNode();
 final FocusNode _passwordFocusNode = FocusNode();

TextField(
        decoration: InputDecoration(
            labelText: 'Email',
            hintText: 'test@test.com',
            errorText: emailErrorText),
        textInputAction: TextInputAction.next,
        keyboardType: TextInputType.emailAddress,
        controller: _emailController,
        focusNode: _emailFocusNode,
        onEditingComplete: _newFocusNode

TextField(
        decoration: InputDecoration(
          labelText: 'Password',
          errorText: passwordErrorText,
        ),
        obscureText: true,
        textInputAction: TextInputAction.done,
        controller: _passwordController,
        focusNode: _passwordFocusNode,
}

 void _newFocusNode() {
 final newFocus=_emailFocusNode?_passwordFocusNode:_emailFocusNode;
FocusScope.of(context).requestFocus(newFocus);
}
Related