Text Input
How are key events sent from the keyboard?
SystemChannels.keyEventexposes a messaging channel that receives raw key data whenever the platform produces keyboard events.RawKeyboardsubscribes to this channel and forwards incoming messages asRawKeyEventinstances (which encapsulateRawKeyEventData). Physical and logical interpretations of the event are exposed viaRawKeyEvent.physicalKeyandRawKeyEvent.logicalKey, respectively. The character produced is available asRawKeyEvent.characterbut only forRawKeyDownEventevents. This field accounts for modifier keys / past keystrokes producing null for invalid combinations or a dart string, otherwise.The physical key identifies the actual position of the key that was struck, expressed as the equivalent key on a standard
QWERTYkeyboard. The logical key ignores position, taking into account any mappings or layout changes to produce the actual key the user intended.Subclasses of
RawKeyEventDatainterpret platform-specific data to categorize the keystroke in a portable way (RawKeyEventDataAndroid,RawKeyEventDataMacOs)
What is an IME?
IME?IMEstands for “input method editor,” which corresponds to any sort of on-screen text editing interface, such as the software keyboard. There can only be one activeIMEat a time.
How does Flutter interact with IMEs?
Flutter interact with IMEs?SystemChannels.textInputexposes a method channel that implements a transactional interface for interacting with anIME. Operations are scoped to a given transaction (client), which is implicit once created. Outbound methods support configuring theIME, showing/hiding UI, and update editing state (including selections); inbound methods handleIMEactions and editing changes. Convenient wrappers for this protocol make much of this seamless.
What are the building blocks for interacting with an IME?
IME?TextInput.attachfederates access to theIME, setting the current client (transaction) that can interact with the keyboard.TextInputClientis an interface to receive information from theIME. Once attached, clients are notified via method invocation when actions are invoked, the editing value is updated, or the cursor is moved.TextInputConnectionis returned byTextInput.attachand allows theIMEto be altered. In particular, the editing state can be changed, theIMEshown, and the connection closed. Once closed, if no other client attaches within the current animation frame, theIMEwill also be hidden.TextInputConfigurationencapsulates configuration data sent to theIMEwhen a client attaches. This includes the desired input type (e.g., “datetime”, “emailAddress”, “phone”) for which to optimize theIME, whether to enable autocorrect, whether to obscure input, the default action, capitalization mode (TextCapitalization), and more.TextInputActionenumerates the set of special actions supported on all platforms (e.g., “emergencyCall”, “done”, “next”). Actions may only be used on platforms that support them. Actions have no intrinsic meaning; developers determine how to respond to actions themselves.TextEditingValuerepresents the current text, selection, and composing state (range being edited) for a run of text.RawFloatingCursorPointrepresents the position of the “floating cursor” oniOS, a special cursor that appears when the user force presses the keyboard. Its position is reported via the client, including state changes (RawFloatingCursorDragState).
Last updated
Was this helpful?