一种完全关闭键盘而不会失去Textfield Focus的方法

发布于 2025-02-04 02:50:59 字数 332 浏览 4 评论 0 原文

有没有办法在不失去TextField Focus的情况下完全关闭键盘?我正在使用Textfield捕获智能手机内置的物理条形码读取器提供的结果,它在返回值中,但我想隐藏键盘。我尝试了许多方法,但是找不到一个好的解决方案。

您的最终解决方案是以下代码。但是,由于应用程序中没有州管理,因此每次刷新页面时,键盘都会迅速打开并关闭。

 @override
 Widget build(BuildContext context) {

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

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(..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦亿 2025-02-11 02:50:59

要隐藏键盘并保持光标可见,请将ROADONLY设置为true,并向true显示

TextFormField(
  showCursor: true,
  readOnly: true),

flutter /essove/#16863

To hide the keyboard and keep the cursor visible, set readOnly to true and show the cursor to true

TextFormField(
  showCursor: true,
  readOnly: true),

See flutter/issues/#16863

抹茶夏天i‖ 2025-02-11 02:50:59

您可以设置键盘键:参数为 textInputtype.none 。这将保留重点。随着文本字段仍然可以编辑,请继续访问,但没有显示键盘。

You can set keyboardType: parameter to TextInputType.none. This will retain focus. Keep access as the TextField is still editable but no keyboard is shown.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文