flutter/examples/widgets/navigation.dart
Adam Barth 99e115d06c Settings menu item in stock2 doesn't work
The underlying problem is that we lacked a RenderObjectWrapper for the
RenderView, which meant we couldn't handle changing the RenderObject that was
the root of the RenderView. This CL introduces a RenderViewWrapper and uses it
in a new AppContainer widget root. This change allows us to make App a
non-magical Component that is inserted into the AppContainer in the newly
introduced runApp function.

R=ianh@google.com

Review URL: https://codereview.chromium.org/1184823006.
2015-06-17 12:36:56 -07:00

78 lines
2.1 KiB
Dart

// Copyright 2015 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:sky/widgets/basic.dart';
import 'package:sky/widgets/navigator.dart';
import 'package:sky/widgets/transition.dart';
import 'package:sky/widgets/raised_button.dart';
List<Route> routes = [
new Route(
name: 'home',
builder: (navigator) => new Container(
padding: const EdgeDims.all(20.0),
decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)),
child: new Block([
new Text("You are at home"),
new RaisedButton(
key: 'b',
child: new Text('GO SHOPPING'),
onPressed: () => navigator.pushNamed('shopping')
),
new RaisedButton(
key: 'a',
child: new Text('START ADVENTURE'),
onPressed: () => navigator.pushNamed('adventure')
)
])
)
),
new Route(
name: 'shopping',
builder: (navigator) => new Container(
padding: const EdgeDims.all(20.0),
decoration: new BoxDecoration(backgroundColor: const Color(0xFFBF5FFF)),
child: new Block([
new Text("Village Shop"),
new RaisedButton(
key: 'a',
child: new Text('RETURN HOME'),
onPressed: () => navigator.back()
),
new RaisedButton(
key: 'b',
child: new Text('GO TO DUNGEON'),
onPressed: () => navigator.push(routes[2])
)
])
)
),
new Route(
name: 'adventure',
builder: (navigator) => new Container(
padding: const EdgeDims.all(20.0),
decoration: new BoxDecoration(backgroundColor: const Color(0xFFDC143C)),
child: new Block([
new Text("Monster's Lair"),
new RaisedButton(
child: new Text('NO WAIT! GO BACK!'),
onPressed: () => navigator.pop()
)
])
)
)
];
class NavigationExampleApp extends App {
NavigationState _navState = new NavigationState(routes);
Widget build() {
return new Flex([new Navigator(_navState)]);
}
}
void main() {
runApp(new NavigationExampleApp());
}