简体   繁体   English

是否可以防止键盘关闭?

[英]Is it possible to prevent keyboard dismissing?

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.为了使自动填充在 iOS 上工作,我必须使用带有本机键盘的文本字段。 But the keyboard can be hidden by user on Android by tapping on back button.但是用户可以通过点击后退按钮在 Android 上隐藏键盘。

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

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.您可以使用WillPopScope小部件包装您的Scaffold ,然后您可以对onWillPop中的按钮的后退执行任何操作,无论它是 android 还是 iOS。

By clicking the back button, it is not possible to stop Android from dismissing the keyboard.通过单击后退按钮,无法阻止 Android 关闭键盘。 You as a developer have no control over this because of how the Android operating system behaves.由于 Android 操作系统的行为方式,您作为开发人员无法控制这一点。 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.可以通过显示充满屏幕的消息或模式来要求用户保持键盘可见,但您也可以尝试这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM