flutter/dev/manual_tests/raw_keyboard.dart
James Robinson a95c9fdb58 Isolate imports of generated Dart code from generated path (#5960)
This rewrites imports of various mojom.dart files from the Flutter
engine repo to instead import normal-looking dart files from the
(new) flutter_services package. This package handles exporting the
correct symbols from generated code wherever that may live.

Includes an engine roll to 3551e7a48e2e336777b15c7637af92fd7605b6c5
which contains the new flutter_services package.
2016-09-21 14:00:29 -07:00

76 lines
1.8 KiB
Dart

// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_services/input_event.dart' as mojom;
GlobalKey _key = new GlobalKey();
void main() {
runApp(new MaterialApp(
title: "Hardware Key Demo",
home: new Scaffold(
appBar: new AppBar(
title: new Text("Hardware Key Demo")
),
body: new Material(
child: new RawKeyboardDemo(
key: _key
)
)
)
));
}
class RawKeyboardDemo extends StatefulWidget {
RawKeyboardDemo({ GlobalKey key }) : super(key: key);
@override
_HardwareKeyDemoState createState() => new _HardwareKeyDemoState();
}
class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
mojom.InputEvent _event;
void _handleKey(mojom.InputEvent event) {
setState(() {
_event = event;
});
}
@override
Widget build(BuildContext context) {
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: Typography.black.display1)
)
);
} else if (_event == null) {
child = new Center(
child: new Text('Press a key', style: Typography.black.display1)
);
} else {
child = new Column(
children: <Widget>[
new Text('${_event.type}', style: Typography.black.body2),
new Text('${_event.keyData.keyCode}', style: Typography.black.display4)
],
mainAxisAlignment: MainAxisAlignment.center
);
}
return new RawKeyboardListener(
focused: focused,
onKey: _handleKey,
child: child
);
}
}