RawKeyboardListener to detect Enter key on a web form does not work

Viewed 9

I am trying to submit a web form on Enter key (not a TextField but an EmailField and PasswordField!)

I read through many similar question that ask how to submit a form using the Enter Key on flutter for web, and I cannot make it work if the field is either PasswordField or EmailField.

The latest code I tried it looks like this one:

      Widget build(BuildContext context) {
        final focusNode = FocusNode(onKey: (node, event) {
          if (event.isKeyPressed(LogicalKeyboardKey.enter)) {
            // prevent passing the event into the TextField
            return KeyEventResult.handled;
          }
          // pass the event to the TextField
          return KeyEventResult.ignored;
        });
        return Form(
              key: _formKey,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                   RawKeyboardListener(
                      focusNode: focusNode,
                      onKey: (event) {
                        if (event.isKeyPressed(LogicalKeyboardKey.enter)) {
                          _signIn();
                        }
                      },
                      child:
                          EmailTextField(controller: _emailTextEditingController)),
                     ....

Please note that the events are properly captured on iOS and other platforms, but not on the web platform.

Related: Detect 'enter key' press in flutter

0 Answers
Related