Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Disable hardware keyboard regularity warning by default#181894

Merged
auto-submit[bot] merged 10 commits intoflutter:masterfrom
dkwingsmt:remove-keyevent-assertion
Feb 10, 2026
Merged

Disable hardware keyboard regularity warning by default#181894
auto-submit[bot] merged 10 commits intoflutter:masterfrom
dkwingsmt:remove-keyevent-assertion

Conversation

@dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented Feb 4, 2026

Suppresses #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 #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-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.

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Feb 4, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dkwingsmt
Copy link
Contributor Author

@justinmc @loic-sharma Would any of you like to review this PR?

@github-actions github-actions bot added the a: tests "flutter test", flutter_test, or one of our tests label Feb 5, 2026
@loic-sharma loic-sharma self-requested a review February 6, 2026 19:11
Comment on lines +531 to +532
// Only checks physical key here and don't reject based on logical key,
// since otherwise the key will never be released.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we process a KeyRepeatEvent if it's not in the pressed keys? I'd imagine that means we missed a KeyDownEvent?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is indeed correct, I'd consider adding a quick comment explaining why as that's not immediately obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an awesome insight. Thank you so much for spotting that. We should indeed process KeyRepeatEvent whose key is not pressed.

Copy link
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with one question on why KeyRepeatEvents aren't processed if the key isn't known to be pressed.

@dkwingsmt
Copy link
Contributor Author

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.

@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 10, 2026
@auto-submit auto-submit bot added this pull request to the merge queue Feb 10, 2026
Merged via the queue into flutter:master with commit aa4339b Feb 10, 2026
73 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 10, 2026
rickhohler pushed a commit to rickhohler/flutter that referenced this pull request Feb 19, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants