Update raw keyboard example (#6871)
We now center the body correctly and handle Fuchsia key events. Also, add support for modifiers.
This commit is contained in:
@@ -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> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user