Add full support for hardware keyboards (Chromebook, Android tablets, etc) that don't alter screen UI (#765)

pull/769/head
Michael Allen 3 years ago committed by GitHub
parent 679febd5ca
commit 8481785739
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      lib/src/widgets/raw_editor.dart

@ -577,6 +577,8 @@ class RawEditorState extends EditorState
_onChangeTextEditingValue(!_hasFocus);
}
});
HardwareKeyboard.instance.addHandler(_hardwareKeyboardEvent);
}
});
}
@ -585,6 +587,27 @@ class RawEditorState extends EditorState
widget.focusNode.addListener(_handleFocusChanged);
}
// KeyboardVisibilityController only checks for keyboards that
// adjust the screen size. Also watch for hardware keyboards
// that don't alter the screen (i.e. Chromebook, Android tablet
// and any hardware keyboards from an OS not listed in isKeyboardOS())
bool _hardwareKeyboardEvent(KeyEvent _) {
if (!_keyboardVisible) {
// hardware keyboard key pressed. Set visibility to true
_keyboardVisible = true;
// update the editor
_onChangeTextEditingValue(!_hasFocus);
}
// remove the key handler - it's no longer needed. If
// KeyboardVisibilityController clears visibility, it wil
// also enable it when appropriate.
HardwareKeyboard.instance.removeHandler(_hardwareKeyboardEvent);
// we didn't handle the event, just needed to know a key was pressed
return false;
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
@ -657,6 +680,7 @@ class RawEditorState extends EditorState
void dispose() {
closeConnectionIfNeeded();
_keyboardVisibilitySubscription?.cancel();
HardwareKeyboard.instance.removeHandler(_hardwareKeyboardEvent);
assert(!hasConnection);
_selectionOverlay?.dispose();
_selectionOverlay = null;

Loading…
Cancel
Save