Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable backspace for mobile platform. #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

linhanyu
Copy link
Contributor

I think it's bad idea to totally reject key stroke. It made many functional keybinding not
usable. Just accept it as PC does and throw those situation to
application developer is more resonable.

I think it's bad idea to totally reject key stroke. It made many functional keybinding not
usable. Just accept it as PC does and throw those situation to
application developer is more resonable.
@xtyxtyx
Copy link
Member

xtyxtyx commented Sep 28, 2021

What soft keyboard do you use?

Different soft keyboards behave quite differently. Some keyboards I tested never generate keyboard events thus it's necessary to do some hack to listen for backspace events.

It will be nice if you can provide more information about your use case(for example: os, keyboard, IME ...) so I can make further investigation.

@linhanyu
Copy link
Contributor Author

What soft keyboard do you use?

Different soft keyboards behave quite differently. Some keyboards I tested never generate keyboard events thus it's necessary to do some hack to listen for backspace events.

It will be nice if you can provide more information about your use case(for example: os, keyboard, IME ...) so I can make further investigation.

Yes, you're right.
I have tested on my windows PC, android emulator, and my android phone.

In my emulator, keyboards never generate keyboard events so I have set acceptKeyboardStorke to true. However, It made Enter send twice.So I removed onTextEdit.

Last day night, I have test on my android phone, It seems some problem after delete onTextEdit. It make input failed, So I add it back.

so, The problem is:

  1. on my android phone, I have to open acceptKeyStroke to get back press event.
  2. on my PC emulator, enter triggered twice after set acceptKeyStroke to true.

hoppfully helpful

@linhanyu
Copy link
Contributor Author

My android phone is Xiaomi 10 Lite, base on Android 11.
My emulator is Pixel 4, base on Android 11

@sand-knight
Copy link

I wish my experience is of any use, and that this is the right place to share it. I'm going to describe why I agree with the pull request and how I managed its consequences inside my android app.

The app I'm writing resembles the pty example. On android 11 crDroid rom, AOSP keyboard works in any case, but:
With acceptKeyStroke = false, on bluetooth keyboard and on Hacker's Keyboard, backspace, ctrl+c, home/end, arrow keys do not work.
With acceptKeyStroke = true, those keys and combos work fine, but the bluetooth keyboard sends Enter twice. Furthermore, when pressing the arrow up key, the terminal correctly loads the previous command, but at the same time, android moves the focus from the terminal to the appbar; the same goes with Tab.
I corrected this last undesired behavior with the following solution. I just started with flutter a month ago, this does not look elegant, but I'm not aware of any side effect with the devices I've described.
I passed this FocusNode to the TerminalView

FocusNode focusNodeToAbsorbKeys = FocusNode(
    canRequestFocus: true,
    descendantsAreFocusable: false,
    onKey: (node, event) {
      LogicalKeyboardKey whatkey = event.logicalKey;
      if (whatkey == LogicalKeyboardKey.enter) return KeyEventResult.handled;
      if (whatkey == LogicalKeyboardKey.tab) return KeyEventResult.handled;
      if (whatkey == LogicalKeyboardKey.arrowUp) return KeyEventResult.handled;
      if (whatkey == LogicalKeyboardKey.arrowDown)
        return KeyEventResult.handled;
      else
        return KeyEventResult.ignored;
    });

If I do not check for the key and unconditionally return KeyEventResult.handled, Digit keys do not work on any keyboard, not even AOSP; and on bluetooth keyboard, all letters do not work.

Thank you for your memorable work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants