KeyBinding class
Key bindings associate key names with Command-style functions.
Key names may be strings like "Shift-Ctrl-Enter"—a key identifier
prefixed with zero or more modifiers. Key identifiers are based on
the strings from Flutter's LogicalKeyboardKey.keyLabel.
Modifiers can be given in any order:
Shift-(ors-)Alt-(ora-)Ctrl-(orc-orControl-)Cmd-(orm-orMeta-)
When a key binding contains multiple key names separated by spaces, it represents a multi-stroke binding, which will fire when the user presses the given keys after each other.
You can use Mod- as a shorthand for Cmd- on Mac and Ctrl- on
other platforms. So Mod-b is Ctrl-b on Linux but Cmd-b on macOS.
Example:
KeyBinding(
key: 'Mod-s',
run: (view) {
saveDocument();
return true;
},
)
Constructors
Properties
- any → bool Function(dynamic view, KeyEvent event)?
-
When this property is present, the function is called for every
key that is not a multi-stroke prefix.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → String?
-
The key name to use for this binding.
final
- linux → String?
-
Key to use specifically on Linux.
final
- mac → String?
-
Key to use specifically on macOS.
final
- platformKey → String?
-
Get the appropriate key for the current platform.
no setter
- preventDefault → bool
-
When set to true (the default is false), this will always prevent the
further handling for the bound key, even if the command(s) return false.
final
- run → Command?
-
The command to execute when this binding is triggered.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scope → String?
-
By default, key bindings apply when focus is on the editor content
(the
"editor"scope).final - shift → Command?
-
When given, this defines a second binding, using the (possibly
platform-specific) key name prefixed with
Shift-to activate this command.final - stopPropagation → bool
-
When set to true,
stopPropagationwill be called on keyboard events that have theirpreventDefaultcalled in response to this key binding.final - win → String?
-
Key to use specifically on Windows.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited