Disable hardware keyboard regularity warning by default#181894
Disable hardware keyboard regularity warning by default#181894auto-submit[bot] merged 10 commits intoflutter:masterfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request disables hardware keyboard regularity warnings by default to improve the developer experience, especially during hot restarts where false errors were common. The warnings are now only shown when debugPrintKeyboardEvents is enabled.
The core change replaces _assertEventIsRegular with _eventIsRegular, which no longer asserts on irregular events but instead returns whether the event should be processed. handleKeyEvent is updated to use this new method, ignoring irregular events and logging a warning in debug mode if enabled.
Additionally, a bug is fixed where KeyRepeatEvent did not update the logical key, which could lead to an inconsistent state if the keyboard layout changed while a key was pressed.
New tests are added to verify that irregular key events are correctly ignored and that the logical key is updated on repeat events.
The changes are well-implemented and address the stated problem effectively. I have one minor suggestion to improve the readability of the new test.
|
@justinmc @loic-sharma Would any of you like to review this PR? |
| // Only checks physical key here and don't reject based on logical key, | ||
| // since otherwise the key will never be released. |
There was a problem hiding this comment.
When I first saw this "don't reject based on logical key" comment, I incorrectly thought this meant "don't check if the map _pressedKeys has a key entry for the logical key". I didn't realize what this instead meant was "don't check if the map's value matches the logical key".
I'd consider moving the second half of this comment down to line 544. Alternatively, consider adding more context to this command. Maybe something like:
| // Only checks physical key here and don't reject based on logical key, | |
| // since otherwise the key will never be released. | |
| // Reject repeat or up events if the physical isn't known to be pressed. | |
| // However, do process these events even if the logical key is mismatched - | |
| // this ensures the key is released or updated to the latest logical key value. |
| } else if (event is KeyRepeatEvent || event is KeyUpEvent) { | ||
| // Only checks physical key here and don't reject based on logical key, | ||
| // since otherwise the key will never be released. | ||
| final bool shouldProcess = _pressedKeys.containsKey(event.physicalKey); |
There was a problem hiding this comment.
Should we process a KeyRepeatEvent if it's not in the pressed keys? I'd imagine that means we missed a KeyDownEvent?
There was a problem hiding this comment.
If this is indeed correct, I'd consider adding a quick comment explaining why as that's not immediately obvious.
There was a problem hiding this comment.
That's an awesome insight. Thank you so much for spotting that. We should indeed process KeyRepeatEvent whose key is not pressed.
loic-sharma
left a comment
There was a problem hiding this comment.
LGTM, with one question on why KeyRepeatEvents aren't processed if the key isn't known to be pressed.
|
I've changed the design, and now all key events are processed with their effect applied to the key pressing state. I find it hard to draw a line between irregular events to be processed and those not. Now this PR simply hides the warnings behind a flag. |
Suppresses flutter#125975 This PR disable hardware keyboard regularity warning unless `debugPrintKeyboardEvents` is set. Keyboard state synchronization has proven extremely difficult, largely due to the asynchronous communication between the engine and framework. Unfortunately, I haven't had the bandwidth to fix it, causing developers to experience false errors during hot restarts. It's time to acknowledge this and prioritize development experience over idealism by disabling these useless warnings. I apologize for the issues I've caused over the years. Perhaps someday we can make this work with a fully regular event stream. Replaces flutter#181719 . ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Suppresses #125975
This PR disable hardware keyboard regularity warning unless
debugPrintKeyboardEventsis set.Keyboard state synchronization has proven extremely difficult, largely due to the asynchronous communication between the engine and framework. Unfortunately, I haven't had the bandwidth to fix it, causing developers to experience false errors during hot restarts. It's time to acknowledge this and prioritize development experience over idealism by disabling these useless warnings.
I apologize for the issues I've caused over the years. Perhaps someday we can make this work with a fully regular event stream.
Replaces #181719 .
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.