'flutter can't receive any RawKeyEvent on ios mobile

This is my code

return RawKeyboardListener(
      focusNode: _listFocusNodeKeyListener[index],
      onKey: (event) {
        if (event.runtimeType == RawKeyUpEvent) {
          if (event.data.logicalKey == LogicalKeyboardKey.arrowLeft) {
            _prev(index);
          } else if (event.data.logicalKey == LogicalKeyboardKey.arrowRight) {
            _next(index);
          } else if (event.data.logicalKey == LogicalKeyboardKey.backspace) {
            if (_listControllerText[index].text.isEmpty) _prev(index);
          }
        }
      },
      child: Container(
        decoration: BoxDecoration(
          color: IMColors.bgSearchBar,
          borderRadius: BorderRadius.all(Radius.circular(10)),
        ),
        padding: EdgeInsets.only(top: 8),
        child: TextField(
          keyboardType: widget.keyboardType,
          inputFormatters: widget.digitsOnly
              ? <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly]
              : null,
          maxLines: 1,
          maxLength: widget.length - index,
          controller: _listControllerText[index],
          focusNode: _listFocusNode[index],
          showCursor: true,
          cursorColor: widget.cursorColor,
          // maxLengthEnforcement: MaxLengthEnforcement.enforced,
          // autocorrect: false,
          textAlign: TextAlign.center,
          autofocus: widget.autofocus,
          style: widget.textStyle,
          expands: false,
          decoration: InputDecoration(
            border: InputBorder.none,
            // fillColor: widget.fillColor,
            // enabledBorder: null,
            // focusedBorder: null,
            counterText: '',
            // contentPadding: EdgeInsets.all(((widget.itemSize * 2) / 10)),
            // errorMaxLines: 1,
          ),
         
        ),
      ),
    );

in the onKey event mehtod,I can't receive any event while user is typing on ios,but it works on Android. And I found the ServicesBinding won't send any message abount keyEvnet on ios. The source code of _initKeyboard following:

void _initKeyboard() {
    _keyboard = HardwareKeyboard();
    _keyEventManager = KeyEventManager(_keyboard, RawKeyboard.instance);
    window.onKeyData = _keyEventManager.handleKeyData;
    SystemChannels.keyEvent.setMessageHandler(_keyEventManager.handleRawKeyMessage);
  }

The handleRawKeyMessage dont work while user is typing. Does anyone konw why and how to listen to the key events on ios?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source