Keyboard key
A keyboard key label shows which key runs a command. Place it beside the name of the command, within the part of the interface where the shortcut works.
Reset a counter
#Activate Count one a few times. With focus still in the example, press Escape to reset the count.
components/keyboard-key/appliance/reset_counter.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
import 'package:flutter/services.dart' show LogicalKeyboardKey;
class ResetCounter extends StatefulWidget {
const ResetCounter({super.key});
@override
State<ResetCounter> createState() => _ResetCounterState();
}
class _ResetCounterState extends State<ResetCounter> {
static const reset = SingleActivator(LogicalKeyboardKey.escape);
int count = 0;
@override
Widget build(BuildContext context) => CallbackShortcuts(
bindings: {reset: () => setState(() => count = 0)},
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ApplianceButton('Count one', onPressed: () => setState(() => count++)),
const SizedBox(height: 12),
const Wrap(
alignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 8,
children: [ApplianceKbd.shortcut(reset), Text('Reset count')],
),
const SizedBox(height: 12),
Text('Count: $count'),
],
),
);
}
Parameters
ApplianceKbd API ↗shortcut- Escape key shown beside the reset command.
Shared behaviour
- Keyboard and focus. Tab to Count one and use Enter or Space to increment. The displayed key is a hint. Its Escape shortcut works while the button holds focus.
- Screen readers. Read the key label together with “Reset count”. The count appears after the hint.
- Direction and type. The key and its description follow reading order and can wrap at larger text sizes.