Commit 1424f351 authored by Adam Barth's avatar Adam Barth

Update navigation example after Navigator changes

Now this example uses the App widget to drive the adventure game.
parent a01aa6ff
......@@ -2,31 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:sky/material.dart';
import 'package:sky/src/fn3.dart';
List<Route> routes = [
new Route(
name: 'home',
builder: (navigator, route) => new Container(
final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
'/': (NavigatorState navigator, Route route) => new Container(
padding: const EdgeDims.all(30.0),
decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)),
child: new Column([
new Text("You are at home"),
new RaisedButton(
child: new Text('GO SHOPPING'),
onPressed: () => navigator.pushNamed('shopping')
onPressed: () => navigator.pushNamed('/shopping')
),
new RaisedButton(
child: new Text('START ADVENTURE'),
onPressed: () => navigator.pushNamed('adventure')
onPressed: () => navigator.pushNamed('/adventure')
)],
justifyContent: FlexJustifyContent.center
)
)
),
new Route(
name: 'shopping',
builder: (navigator, route) => new Container(
'/shopping': (NavigatorState navigator, Route route) => new Container(
padding: const EdgeDims.all(20.0),
decoration: new BoxDecoration(backgroundColor: const Color(0xFFBF5FFF)),
child: new Column([
......@@ -37,15 +33,12 @@ List<Route> routes = [
),
new RaisedButton(
child: new Text('GO TO DUNGEON'),
onPressed: () => navigator.push(routes[2])
onPressed: () => navigator.pushNamed('/adventure')
)],
justifyContent: FlexJustifyContent.center
)
)
),
new Route(
name: 'adventure',
builder: (navigator, route) => new Container(
'/adventure': (NavigatorState navigator, Route route) => new Container(
padding: const EdgeDims.all(20.0),
decoration: new BoxDecoration(backgroundColor: const Color(0xFFDC143C)),
child: new Column([
......@@ -57,32 +50,17 @@ List<Route> routes = [
justifyContent: FlexJustifyContent.center
)
)
)
];
class NavigationExampleApp extends StatefulComponent {
NavigationExampleAppState createState() => new NavigationExampleAppState();
}
class NavigationExampleAppState extends State<NavigationExampleApp> {
NavigatorHistory _history = new NavigatorHistory(routes);
};
void onBack() {
if (_history.hasPrevious()) {
setState(() {
_history.pop();
});
} else {
// TODO(abarth): Integrate with the system navigator.
// super.onBack();
}
}
Widget build(BuildContext context) {
return new Row([new Navigator(_history)]);
}
}
final ThemeData theme = new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.purple
);
void main() {
runApp(new NavigationExampleApp());
runApp(new App(
title: 'Navigation Example',
theme: theme,
routes: routes
));
}
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