Home > OS >  Is it possible to prevent keyboard dismissing?
Is it possible to prevent keyboard dismissing?

Time:01-31

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) {
    ...
  },
)

CodePudding user response:

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.

CodePudding user response:

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.

  • Related