RawKeyboardListener not fired any event in Flutter web

785

I think you need to add this line to the top of your builder method:

FocusScope.of(context).requestFocus(focusNode);

Your code should look like this:

Container(
  child: StreamProvider<Item>.value(
    value: stream
    child: Consumer<Item>(
      builder: (_, item, __) {
        FocusScope.of(context).requestFocus(focusNode); // Add this line

        return RawKeyboardListener(
          focusNode: focusNode,
          onKey: (event) {
            print(event); // NOT PRINTED!!
          }
          child: TextField(
            controller: controller,
            ...
          ),
        );
      }
    ),
  ),
),
Share:
785
BambinoUA
Author by

BambinoUA

Expirienced in: Dart/Flutter WinDev/WebDev/WinDev Mobile PHP Clarion for Windows Microsoft C#

Updated on December 20, 2022

Comments

  • BambinoUA
    BambinoUA over 1 year

    Here it is simple code inside some widget. The RawKeyboardListener's onKey is not triggered! So the question why? Is it a bug?

    Container(
      child: StreamProvider<Item>.value(
        value: stream
        child: Consumer<Item>(
          builder: (_, item, __) {
            return RawKeyboardListener(
              focusNode: focusNode,
              onKey: (event) {
                print(event); // NOT PRINTED!!
              }
              child: TextField(
                controller: controller,
                ...
              ),
            );
          }
        ),
      ),
    ),
    

    P.S. Flutter is 1.17.0-3.2pre, Dart is 2.8.0-dev.20.10