Commit 5801119d authored by Adam Barth's avatar Adam Barth Committed by GitHub

Update raw keyboard example (#6871)

We now center the body correctly and handle Fuchsia key events. Also, add
support for modifiers.
parent 9cfde147
......@@ -14,7 +14,7 @@ void main() {
appBar: new AppBar(
title: new Text("Hardware Key Demo")
),
body: new Material(
body: new Center(
child: new RawKeyboardDemo(
key: _key
)
......@@ -42,28 +42,28 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
@override
Widget build(BuildContext context) {
final TextTheme textTheme = Theme.of(context).textTheme;
bool focused = Focus.at(context);
final bool focused = Focus.at(context);
Widget child;
if (!focused) {
child = new GestureDetector(
onTap: () {
Focus.moveTo(config.key);
},
child: new Center(
child: new Text('Tap to focus', style: textTheme.display1),
),
child: new Text('Tap to focus', style: textTheme.display1),
);
} else if (_event == null) {
child = new Center(
child: new Text('Press a key', style: textTheme.display1),
);
child = new Text('Press a key', style: textTheme.display1);
} else {
int codePoint;
int keyCode;
int hidUsage;
final RawKeyEventData data = _event.data;
if (data is RawKeyEventDataAndroid) {
codePoint = data.codePoint;
keyCode = data.keyCode;
} else if (data is RawKeyEventDataFuchsia) {
codePoint = data.codePoint;
hidUsage = data.hidUsage;
}
child = new Column(
mainAxisAlignment: MainAxisAlignment.center,
......@@ -71,6 +71,7 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
new Text('${_event.runtimeType}', style: textTheme.body2),
new Text('codePoint: $codePoint', style: textTheme.display4),
new Text('keyCode: $keyCode', style: textTheme.display4),
new Text('hidUsage: $hidUsage', style: textTheme.display4),
],
);
}
......@@ -81,3 +82,4 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
);
}
}
......@@ -70,6 +70,7 @@ class RawKeyEventDataFuchsia extends RawKeyEventData {
const RawKeyEventDataFuchsia({
this.hidUsage: 0,
this.codePoint: 0,
this.modifiers: 0,
});
/// The USB HID usage.
......@@ -81,6 +82,12 @@ class RawKeyEventDataFuchsia extends RawKeyEventData {
///
/// If there is no unicode code point, this value is zero.
final int codePoint;
/// The modifiers that we present when the key event occured.
///
/// See <https://fuchsia.googlesource.com/mozart/+/master/services/input/input_event_constants.fidl>
/// for the numerical values of the modifiers.
final int modifiers;
}
/// Base class for raw key events.
......@@ -138,6 +145,7 @@ RawKeyEvent _toRawKeyEvent(Map<String, dynamic> message) {
data = new RawKeyEventDataFuchsia(
hidUsage: message['hidUsage'] ?? 0,
codePoint: message['codePoint'] ?? 0,
modifiers: message['modifiers'] ?? 0,
);
break;
default:
......
......@@ -38,6 +38,7 @@ void main() {
'keymap': 'fuchsia',
'hidUsage': 0x04,
'codePoint': 0x64,
'modifiers': 0x08,
});
await tester.idle();
......@@ -48,5 +49,6 @@ void main() {
RawKeyEventDataFuchsia typedData = events[0].data;
expect(typedData.hidUsage, 0x04);
expect(typedData.codePoint, 0x64);
expect(typedData.modifiers, 0x08);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment