-
Notifications
You must be signed in to change notification settings - Fork 28.7k
Explain the "patching" protocol in KeyMessageManager.keyMessageHandler
and add an example
#105280
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
Explain the "patching" protocol in KeyMessageManager.keyMessageHandler
and add an example
#105280
Conversation
KeyMessageManager.keyMessageHandler
and add an exampleKeyMessageManager.keyMessageHandler
and add an example
@dkwingsmt looking at |
The short answer is, you only use either the stream of To handle both at the same time, check out the introduction to Event Results updated in this PR, as well as
It is due to the new event model adopted by One of them, for example, is modifier synchronization. If you press In the In the To summarize what happens,
And it is needed to pack the |
Is there a reason that only a single You mentioned the |
Every native event corresponds to one
There are quite a few things we'd like to break with this new keyboard system, not only the event object, but also types ( |
(triage) @dkwingsmt Do you still have plans for this PR? |
FYI @dkwingsmt - Despite us not ending up using this in super_editor, I do plain to use this capability to show popup indications for what the user presses, so that devs can debug their keyboard behavior. So I do think there are use-cases for this, and a public example is a good idea. |
Thanks for letting me know! Yeah I was hesitating of committing to this since I couldn't think of more usage. |
Let me add some tests and I'll land this PR. |
f5c404b
to
77ec229
Compare
cc @matthew-carroll |
// This example app demonstrates a use case of patching | ||
// `KeyEventManager.keyMessageHandler`: be notified of key events that are not | ||
// handled by any focus handlers (such as shortcuts). | ||
// | ||
// See [KeyEventManager.keyMessageHandler]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't link in the IDE, so you don't need the []
Also, Because we don't want to maintain two copies of the description that can get out
of date, we tend not to put detailed descriptions here, other that to say what it is
attached to. So, I'd change this to:
// This example app demonstrates a use case of patching | |
// `KeyEventManager.keyMessageHandler`: be notified of key events that are not | |
// handled by any focus handlers (such as shortcuts). | |
// | |
// See [KeyEventManager.keyMessageHandler]. | |
/// Flutter code sample for [KeyEventManager.keyMessageHandler]. |
Co-authored-by: Greg Spencer <[email protected]>
…b.com:dkwingsmt/flutter into explain-key-event-manager-key-message-handler
@gspencergoog I've applied most suggestions, with one question left. Unfortunately we can't link widget layer symbols in |
), | ||
); | ||
|
||
class FallbackDemo extends StatefulWidget { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the term "fallback" mean in terms of a key handler example?
} | ||
|
||
/// A node used by [FallbackKeyEventRegistrar] to register fallback key handlers. | ||
class FallbackFocusNode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A FocusNode
isn't actually required to implement a custom key handler, right? If not, I think the focus configuration that's done in this demo is probably distracting from the root interactions that allow developers to receive key events from the manager.
examples/api/lib/widgets/hardware_keyboard/key_event_manager.0.dart
Outdated
Show resolved
Hide resolved
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
// This example app demonstrates a use case of patching |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would include a description for at least one hypothetical use-case where a developer would want to patch key handling. If you can think of more then one, then I'd mention multiple use-cases. Examples help a lot with gaining context for an example that a developer is about to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really can't think of any, because if there was a usage that was easy to explain and not possible with the current keyboard API, I would have thought about a new API to support it. Even the usage you mentioned, "show popup indications for what the user presses", should be possible with HardwareKeyboard.instance.addHandler
. I will add more documentation to the other methods though. Thanks for your feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…ager-key-message-handler
…ageHandler` and add an example (flutter/flutter#105280)
…ageHandler` and add an example (flutter/flutter#105280)
…ageHandler` and add an example (flutter/flutter#105280)
…ageHandler` and add an example (flutter/flutter#105280)
…ageHandler` and add an example (flutter/flutter#105280)
…ageHandler` and add an example (flutter/flutter#105280)
…ageHandler` and add an example (flutter/flutter#105280)
* 2142b2e Roll Flutter Engine from cd7e2ec4037b to c31036f2381c (1 revision) (flutter/flutter#108299) * 178e444 Revert "Add optional flag to determine assertiveness level in aria announcement for flutter web" (flutter/flutter#108262) * 8a7b359 flutter update-packages --force-upgrade + analyzer fix (flutter/flutter#108198) * b3f5d3f Roll Flutter Engine from c31036f2381c to 54b0ac3059bf (1 revision) (flutter/flutter#108302) * 2f4299a [flutter_tools] Remove unused parameter when connected DAP to VM Service (flutter/flutter#108285) * e74b9b5 Migrate InputDecorator to Material 3 (flutter/flutter#107943) * e3b851a Fix Tamil DateTime representation of AM/PM (flutter/flutter#108185) * 43d6e2b Roll Flutter Engine from 54b0ac3059bf to 705072522c00 (4 revisions) (flutter/flutter#108308) * 6929ad1 Roll Flutter Engine from 705072522c00 to 3964cf62cdf8 (1 revision) (flutter/flutter#108316) * 5f67b47 [iOS] Update template icons (flutter/flutter#107873) * 606954d Added iconSize parameter in ButtonStyle (flutter/flutter#108268) * b3814c7 Roll Flutter Engine from 3964cf62cdf8 to 7f8925b1f6f3 (2 revisions) (flutter/flutter#108320) * ca6cecf Upgrade Gradle and AGP versions to 7.5/7.2 and migrate examples/tests (flutter/flutter#108197) * d155bc1 Revert "Upgrade Gradle and AGP versions to 7.5/7.2 and migrate examples/tests (#108197)" (flutter/flutter#108349) * 4056d3f Explain the "patching" protocol in `KeyMessageManager.keyMessageHandler` and add an example (flutter/flutter#105280) * b035ef1 [flutter_tools] Remove more shuffles (flutter/flutter#107759) * be14858 Roll Flutter Engine from 7f8925b1f6f3 to 8eca26d130a2 (1 revision) (flutter/flutter#108326) * 3eb638f Roll Flutter Engine from 8eca26d130a2 to f1f9b4de82b6 (5 revisions) (flutter/flutter#108350) * 401b556 Roll Flutter Engine from f1f9b4de82b6 to 11d927ac3e9b (2 revisions) (flutter/flutter#108353) * 925bee9 Roll Flutter Engine from 11d927ac3e9b to 5dcaeae6561b (1 revision) (flutter/flutter#108356) * 5d31b07 [flutter_tools] [dap] Ensure DAP sends app.stop/app.detach during terminate (flutter/flutter#108310) * c8b5d10 Roll Flutter Engine from 5dcaeae6561b to 89e117b89c63 (1 revision) (flutter/flutter#108367) * e3d08fb Hide the debug banner in the PopupMenuButton example (flutter/flutter#108324)
…er` and add an example (flutter#105280)
* 2142b2e Roll Flutter Engine from cd7e2ec4037b to c31036f2381c (1 revision) (flutter/flutter#108299) * 178e444 Revert "Add optional flag to determine assertiveness level in aria announcement for flutter web" (flutter/flutter#108262) * 8a7b359 flutter update-packages --force-upgrade + analyzer fix (flutter/flutter#108198) * b3f5d3f Roll Flutter Engine from c31036f2381c to 54b0ac3059bf (1 revision) (flutter/flutter#108302) * 2f4299a [flutter_tools] Remove unused parameter when connected DAP to VM Service (flutter/flutter#108285) * e74b9b5 Migrate InputDecorator to Material 3 (flutter/flutter#107943) * e3b851a Fix Tamil DateTime representation of AM/PM (flutter/flutter#108185) * 43d6e2b Roll Flutter Engine from 54b0ac3059bf to 705072522c00 (4 revisions) (flutter/flutter#108308) * 6929ad1 Roll Flutter Engine from 705072522c00 to 3964cf62cdf8 (1 revision) (flutter/flutter#108316) * 5f67b47 [iOS] Update template icons (flutter/flutter#107873) * 606954d Added iconSize parameter in ButtonStyle (flutter/flutter#108268) * b3814c7 Roll Flutter Engine from 3964cf62cdf8 to 7f8925b1f6f3 (2 revisions) (flutter/flutter#108320) * ca6cecf Upgrade Gradle and AGP versions to 7.5/7.2 and migrate examples/tests (flutter/flutter#108197) * d155bc1 Revert "Upgrade Gradle and AGP versions to 7.5/7.2 and migrate examples/tests (#108197)" (flutter/flutter#108349) * 4056d3f Explain the "patching" protocol in `KeyMessageManager.keyMessageHandler` and add an example (flutter/flutter#105280) * b035ef1 [flutter_tools] Remove more shuffles (flutter/flutter#107759) * be14858 Roll Flutter Engine from 7f8925b1f6f3 to 8eca26d130a2 (1 revision) (flutter/flutter#108326) * 3eb638f Roll Flutter Engine from 8eca26d130a2 to f1f9b4de82b6 (5 revisions) (flutter/flutter#108350) * 401b556 Roll Flutter Engine from f1f9b4de82b6 to 11d927ac3e9b (2 revisions) (flutter/flutter#108353) * 925bee9 Roll Flutter Engine from 11d927ac3e9b to 5dcaeae6561b (1 revision) (flutter/flutter#108356) * 5d31b07 [flutter_tools] [dap] Ensure DAP sends app.stop/app.detach during terminate (flutter/flutter#108310) * c8b5d10 Roll Flutter Engine from 5dcaeae6561b to 89e117b89c63 (1 revision) (flutter/flutter#108367) * e3d08fb Hide the debug banner in the PopupMenuButton example (flutter/flutter#108324)
* 2142b2e Roll Flutter Engine from cd7e2ec4037b to c31036f2381c (1 revision) (flutter/flutter#108299) * 178e444 Revert "Add optional flag to determine assertiveness level in aria announcement for flutter web" (flutter/flutter#108262) * 8a7b359 flutter update-packages --force-upgrade + analyzer fix (flutter/flutter#108198) * b3f5d3f Roll Flutter Engine from c31036f2381c to 54b0ac3059bf (1 revision) (flutter/flutter#108302) * 2f4299a [flutter_tools] Remove unused parameter when connected DAP to VM Service (flutter/flutter#108285) * e74b9b5 Migrate InputDecorator to Material 3 (flutter/flutter#107943) * e3b851a Fix Tamil DateTime representation of AM/PM (flutter/flutter#108185) * 43d6e2b Roll Flutter Engine from 54b0ac3059bf to 705072522c00 (4 revisions) (flutter/flutter#108308) * 6929ad1 Roll Flutter Engine from 705072522c00 to 3964cf62cdf8 (1 revision) (flutter/flutter#108316) * 5f67b47 [iOS] Update template icons (flutter/flutter#107873) * 606954d Added iconSize parameter in ButtonStyle (flutter/flutter#108268) * b3814c7 Roll Flutter Engine from 3964cf62cdf8 to 7f8925b1f6f3 (2 revisions) (flutter/flutter#108320) * ca6cecf Upgrade Gradle and AGP versions to 7.5/7.2 and migrate examples/tests (flutter/flutter#108197) * d155bc1 Revert "Upgrade Gradle and AGP versions to 7.5/7.2 and migrate examples/tests (#108197)" (flutter/flutter#108349) * 4056d3f Explain the "patching" protocol in `KeyMessageManager.keyMessageHandler` and add an example (flutter/flutter#105280) * b035ef1 [flutter_tools] Remove more shuffles (flutter/flutter#107759) * be14858 Roll Flutter Engine from 7f8925b1f6f3 to 8eca26d130a2 (1 revision) (flutter/flutter#108326) * 3eb638f Roll Flutter Engine from 8eca26d130a2 to f1f9b4de82b6 (5 revisions) (flutter/flutter#108350) * 401b556 Roll Flutter Engine from f1f9b4de82b6 to 11d927ac3e9b (2 revisions) (flutter/flutter#108353) * 925bee9 Roll Flutter Engine from 11d927ac3e9b to 5dcaeae6561b (1 revision) (flutter/flutter#108356) * 5d31b07 [flutter_tools] [dap] Ensure DAP sends app.stop/app.detach during terminate (flutter/flutter#108310) * c8b5d10 Roll Flutter Engine from 5dcaeae6561b to 89e117b89c63 (1 revision) (flutter/flutter#108367) * e3d08fb Hide the debug banner in the PopupMenuButton example (flutter/flutter#108324)
This PR rewrites the documentation of
KeyMessageManager.keyMessageHandler
, explains how to properly "patch" the handler, and adds an example that uses it.Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.