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,87 +2,65 @@ ...@@ -2,87 +2,65 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:sky/material.dart';
import 'package:sky/src/fn3.dart'; import 'package:sky/src/fn3.dart';
List<Route> routes = [ final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
new Route( '/': (NavigatorState navigator, Route route) => new Container(
name: 'home', padding: const EdgeDims.all(30.0),
builder: (navigator, route) => new Container( decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)),
padding: const EdgeDims.all(30.0), child: new Column([
decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)), new Text("You are at home"),
child: new Column([ new RaisedButton(
new Text("You are at home"), child: new Text('GO SHOPPING'),
new RaisedButton( onPressed: () => navigator.pushNamed('/shopping')
child: new Text('GO SHOPPING'), ),
onPressed: () => navigator.pushNamed('shopping') new RaisedButton(
), child: new Text('START ADVENTURE'),
new RaisedButton( onPressed: () => navigator.pushNamed('/adventure')
child: new Text('START ADVENTURE'), )],
onPressed: () => navigator.pushNamed('adventure') justifyContent: FlexJustifyContent.center
)],
justifyContent: FlexJustifyContent.center
)
) )
), ),
new Route( '/shopping': (NavigatorState navigator, Route route) => new Container(
name: 'shopping', padding: const EdgeDims.all(20.0),
builder: (navigator, route) => new Container( decoration: new BoxDecoration(backgroundColor: const Color(0xFFBF5FFF)),
padding: const EdgeDims.all(20.0), child: new Column([
decoration: new BoxDecoration(backgroundColor: const Color(0xFFBF5FFF)), new Text("Village Shop"),
child: new Column([ new RaisedButton(
new Text("Village Shop"), child: new Text('RETURN HOME'),
new RaisedButton( onPressed: () => navigator.pop()
child: new Text('RETURN HOME'), ),
onPressed: () => navigator.pop() new RaisedButton(
), child: new Text('GO TO DUNGEON'),
new RaisedButton( onPressed: () => navigator.pushNamed('/adventure')
child: new Text('GO TO DUNGEON'), )],
onPressed: () => navigator.push(routes[2]) justifyContent: FlexJustifyContent.center
)],
justifyContent: FlexJustifyContent.center
)
) )
), ),
new Route( '/adventure': (NavigatorState navigator, Route route) => new Container(
name: 'adventure', padding: const EdgeDims.all(20.0),
builder: (navigator, route) => new Container( decoration: new BoxDecoration(backgroundColor: const Color(0xFFDC143C)),
padding: const EdgeDims.all(20.0), child: new Column([
decoration: new BoxDecoration(backgroundColor: const Color(0xFFDC143C)), new Text("Monster's Lair"),
child: new Column([ new RaisedButton(
new Text("Monster's Lair"), child: new Text('RUN!!!'),
new RaisedButton( onPressed: () => navigator.pop()
child: new Text('RUN!!!'), )],
onPressed: () => navigator.pop() justifyContent: FlexJustifyContent.center
)],
justifyContent: FlexJustifyContent.center
)
) )
) )
]; };
class NavigationExampleApp extends StatefulComponent { final ThemeData theme = new ThemeData(
NavigationExampleAppState createState() => new NavigationExampleAppState(); brightness: ThemeBrightness.light,
} primarySwatch: Colors.purple
);
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)]);
}
}
void main() { 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