CharacterActivator class Null safety

A shortcut combination that is triggered by a key event that produces a specific character.

Keys often produce different characters when combined with modifiers. For example, it might be helpful for the user to bring up a help menu by pressing the question mark ('?'). However, there is no logical key that directly represents a question mark. Although 'Shift+Slash' produces a '?' character on a US keyboard, its logical key is still considered a Slash key, and hard-coding 'Shift+Slash' in this situation is unfriendly to other keyboard layouts.

For example, CharacterActivator('?') is triggered when a key combination results in a question mark, which is 'Shift+Slash' on a US keyboard, but 'Shift+Comma' on a French keyboard.

In the following example, when a key combination results in a question mark, the counter is increased:

To create a local project with this code sample, run:
flutter create --sample=widgets.CharacterActivator.1 mysample

The alt, control, and meta flags represent whether the respective modifier keys should be held (true) or released (false). They default to false. CharacterActivator cannot check shifted keys, since the Shift key affects the resulting character, and will accept whether either of the Shift keys are pressed or not, as long as the key event produces the correct character.

By default, the activator is checked on all RawKeyDownEvent events for the character in combination with the requested modifier keys. If includeRepeats is false, only the character events with a false RawKeyDownEvent.repeat attribute will be considered.

On macOS and iOS, the alt flag indicates that the Option key (⌥) is pressed. Because the Option key affects the character generated on these platforms, it can be unintuitive to define CharacterActivators for them.

For instance, if you want the shortcut to trigger when Option+s (⌥-s) is pressed, and what you intend is to trigger whenever the character 'ß' is produced, you would use CharacterActivator('ß') or CharacterActivator('ß', alt: true) instead of CharacterActivator('s', alt: true). This is because CharacterActivator('s', alt: true) will never trigger, since the 's' character can't be produced when the Option key is held down.

If what is intended is that the shortcut is triggered when Option+s (⌥-s) is pressed, regardless of which character is produced, it is better to use SingleActivator, as in SingleActivator(LogicalKeyboardKey.keyS, alt: true).

See also:

  • SingleActivator, an activator that represents a single key combined with modifiers, such as Ctrl+C or Ctrl-Right Arrow.
Implemented types
Mixed in types


CharacterActivator(String character, {bool alt = false, bool control = false, bool meta = false, bool includeRepeats = true})
Triggered when the key event yields the given character.


alt bool
Whether either (or both) Alt keys should be held for the character to activate the shortcut.
character String
The character which triggers the shortcut.
control bool
Whether either (or both) Control keys should be held for the character to activate the shortcut.
hashCode int
The hash code for this object.
includeRepeats bool
Whether this activator accepts repeat events of the character.
meta bool
Whether either (or both) Meta keys should be held for the character to activate the shortcut.
runtimeType Type
A representation of the runtime type of the object.
triggers Iterable<LogicalKeyboardKey>?
All the keys that might be the final event to trigger this shortcut.


accepts(RawKeyEvent event, RawKeyboard state) bool
Whether the triggering event and the keyboard state at the time of the event meet required conditions, providing that the event is a triggering event.
debugDescribeKeys() String
Returns a description of the key set that is short and readable.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
serializeForMenu() ShortcutSerialization
Implement this in a ShortcutActivator subclass to allow it to be serialized for use in a PlatformMenuBar.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
toString({DiagnosticLevel minLevel =}) String
A string representation of this object.
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode.


operator ==(Object other) bool
The equality operator.