mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

The 'routes' table is a point of confusion with new developers. By providing a 'home' argument that sets the '/' route, we can delay the point at which we teach developers about 'routes' until the point where they want to have a second route.
76 lines
1.8 KiB
Dart
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:sky_services/sky/input_event.mojom.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
|
|
);
|
|
}
|
|
}
|