Flutter Web上的键盘快捷键

发布于 2025-02-10 17:55:34 字数 587 浏览 1 评论 0原文

我正在将键盘快捷键添加到Flutter Web应用程序中。

我在custom focusableActionDetector中具有形式,其中快捷方式具有这样的形式:

SingleActivator(LogicalKeyboardKey.digit2)

操作是:

CustomActivateIntent: CallbackAction<CustomActivateIntent>(
      onInvoke: (intent) { provider.value = "2"; },)

以相同的形式,我有几个数字textformfield s。要允许编写字符“ 2”,我必须将这些文本字段放在一些新的focusableActionDetector中,否则以前的检测器捕获命令,并且文本字段失去了“ 2”字符,这已经很完全怪异...此外,在任何文本字段中编写文本字段之后,Focus focus ftecter不再起作用。

我认为这可能与焦点系统有关,这对我来说还不清楚。 谁能帮助找到干净的解决方案?

I'm adding keyboard shortcuts to a Flutter web application.

I have a form within a custom FocusableActionDetector where the shortcut has form like this:

SingleActivator(LogicalKeyboardKey.digit2)

and action is like:

CustomActivateIntent: CallbackAction<CustomActivateIntent>(
      onInvoke: (intent) { provider.value = "2"; },)

In the same form I have a couple of numeric TextFormFields. To permit writing the character "2" I have to put these text fields inside some new FocusableActionDetector, otherwise the previous detector catches the command and the text field loses the "2" character, and this is already quite weird... Moreover, after writing in any of the text fields the form focus detector doesn't work anymore.

I think this could be related to the focus system, which is yet not that clear to me.
Can anyone help find a clean solution?

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

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

发布评论

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

评论(1

千秋岁 2025-02-17 17:55:34

我发现了一个解决方法:focusableActionDetector现在先于if语句。代码看起来如下:

// I extract the form to a widget to make it clearer
var searchWidget = SearchWidget();
child: textEditingInProgress
    ? searchWidget
    : FocusableActionDetector(
        child: searchWidget,
        ...,
    ),

texteditingInprogress bool是提供商中的一个字段,由focusnode s属于textcontroller s。

仍然这不是一个完美的解决方案,特别是我想理解为什么以前的方法不起作用。

I found a workaround: the FocusableActionDetector is now preceded by an if statement. The code looks like the following:

// I extract the form to a widget to make it clearer
var searchWidget = SearchWidget();
child: textEditingInProgress
    ? searchWidget
    : FocusableActionDetector(
        child: searchWidget,
        ...,
    ),

The textEditingInProgress bool is a field in a provider and is controlled by the FocusNodes belonging to the TextControllers.

Still this is not a perfect solution, in particular I'd like to understand why the previous approach was not working.

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