skip to Main Content

I have a screen where user must input the code from sms message. In order for autofill to work on iOS I have to use textfield with native keyboard. But the keyboard can be hidden by user on Android by tapping on back button.

Is it possible to prevent the keyboard from dismissing?

Here’s my textfield:

TextField(
  maxLength: 6,
  inputFormatters: [FilteringTextInputFormatter.digitsOnly],
  autofocus: true,
  decoration: const InputDecoration.collapsed(hintText: ''),
  keyboardType: TextInputType.number,
  onChanged: (value) {
    ...
  },
)

2

Answers


  1. You can wrap your Scaffold with WillPopScope widget and then you can perform any action on the back press of the button in onWillPop whether it is android or iOS.

    Login or Signup to reply.
  2. By clicking the back button, it is not possible to stop Android from dismissing the keyboard. You as a developer have no control over this because of how the Android operating system behaves. The user can be asked to keep the keyboard visible by displaying a message or a modal that fills the screen, but you can also try this.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search