Text Input
How are key events sent from the keyboard?
SystemChannels.keyEvent
exposes a messaging channel that receives raw key data whenever the platform produces keyboard events.RawKeyboard
subscribes to this channel and forwards incoming messages asRawKeyEvent
instances (which encapsulateRawKeyEventData
). Physical and logical interpretations of the event are exposed viaRawKeyEvent.physicalKey
andRawKeyEvent.logicalKey
, respectively. The character produced is available asRawKeyEvent.character
but only forRawKeyDownEvent
events. 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
QWERTY
keyboard. The logical key ignores position, taking into account any mappings or layout changes to produce the actual key the user intended.Subclasses of
RawKeyEventData
interpret platform-specific data to categorize the keystroke in a portable way (RawKeyEventDataAndroid
,RawKeyEventDataMacOs
)
What is an IME
?
IME
?IME
stands 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 activeIME
at a time.
How does Flutter
interact with IMEs
?
Flutter
interact with IMEs
?SystemChannels.textInput
exposes 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 handleIME
actions 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.attach
federates access to theIME
, setting the current client (transaction) that can interact with the keyboard.TextInputClient
is 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.TextInputConnection
is returned byTextInput.attach
and allows theIME
to be altered. In particular, the editing state can be changed, theIME
shown, and the connection closed. Once closed, if no other client attaches within the current animation frame, theIME
will also be hidden.TextInputConfiguration
encapsulates configuration data sent to theIME
when 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.TextInputAction
enumerates 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.TextEditingValue
represents the current text, selection, and composing state (range being edited) for a run of text.RawFloatingCursorPoint
represents 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