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
You can wrap your
Scaffold
withWillPopScope
widget and then you can perform any action on the back press of the button inonWillPop
whether it is android or iOS.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.