简体   繁体   English

一种在不丢失文本字段焦点的情况下完全关闭键盘的方法

[英]A way to completely close the keyboard without losing textfield focus

Is there a way to completely close the keyboard without losing textfield focus?有没有办法在不丢失文本字段焦点的情况下完全关闭键盘? I'm using textfield to capture the result provided by a physical barcode reader built into the smartphone, it's in the return value, but I want to hide the keyboard.我正在使用文本字段来捕获智能手机内置的物理条形码阅读器提供的结果,它在返回值中,但我想隐藏键盘。 I tried many methods, but I couldn't find a good solution.我尝试了很多方法,但我找不到一个好的解决方案。

Your final solution was the following code.您的最终解决方案是以下代码。 However, since there is no state management in the application, the keyboard opens and closes quickly every time the page is refreshed.但是,由于应用程序中没有状态管理,因此每次刷新页面时键盘都会快速打开和关闭。

 @override
 Widget build(BuildContext context) {

  SystemChannels.textInput.invokeMethod("TextInput.hide");
  return Scaffold(..

To hide the keyboard and keep the cursor visible, set readOnly to true and show the cursor to true要隐藏键盘并保持光标可见,请将 readOnly 设置为 true 并将光标设置为 true

TextFormField(
  showCursor: true,
  readOnly: true),

See flutter/issues/#16863颤振/问题/#16863

You can set keyboardType: parameter to TextInputType.none .您可以将keyboardType:参数设置为TextInputType.none This will retain focus.这将保持焦点。 Keep access as the TextField is still editable but no keyboard is shown.保持访问,因为 TextField 仍可编辑,但不显示键盘。

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

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