Chromium Code Reviews| Index: sky/sdk/lib/widgets/navigator.dart |
| diff --git a/sky/sdk/lib/widgets/navigator.dart b/sky/sdk/lib/widgets/navigator.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8f0d62be423690ebedcdc12781a7aee80de860be |
| --- /dev/null |
| +++ b/sky/sdk/lib/widgets/navigator.dart |
| @@ -0,0 +1,57 @@ |
| +// 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 'basic.dart'; |
| + |
| +typedef UINode Builder(Navigator navigator); |
|
abarth-chromium
2015/06/16 02:07:55
Please add a blank line below this line.
jackson
2015/06/16 16:46:37
Done.
|
| +abstract class RouteBase { |
| + RouteBase({this.name}); |
| + final String name; |
| + UINode build(Navigator navigator); |
| +} |
| + |
| +class Route extends RouteBase { |
| + Route({String name, this.builder}) : super(name: name); |
| + final Builder builder; |
| + UINode build(Navigator navigator) => builder(navigator); |
| +} |
| + |
| +class Navigator extends Component { |
| + Navigator({Object key, RouteBase initialRoute, this.routes}) |
| + : super(key: key, stateful: true) { |
| + assert(initialRoute != null || routes != null && routes.length > 0); |
| + currentRoute = initialRoute == null ? this.routes[0] : initialRoute; |
|
abarth-chromium
2015/06/16 02:07:54
There's actually a subtle bug in this class. The
jackson
2015/06/16 16:46:37
Done.
|
| + } |
| + |
| + RouteBase currentRoute; |
| + List<RouteBase> routes; |
| + |
| + void syncFields(Navigator source) { |
| + currentRoute = source.currentRoute; |
| + routes = source.routes; |
| + } |
| + |
| + void pushNamedRoute(String name) { |
| + assert(routes != null); |
| + for (RouteBase route in routes) { |
| + if (route.name == name) { |
| + setState(() { |
| + currentRoute = route; |
| + }); |
| + return; |
| + } |
| + } |
| + assert(false); // route not found |
| + } |
| + |
| + void pushRoute(RouteBase route) { |
| + setState(() { |
| + currentRoute = route; |
| + }); |
| + } |
| + |
| + UINode build() { |
| + return currentRoute.build(this); |
|
abarth-chromium
2015/06/16 02:07:54
For example,
if (currentRoute == null)
return r
|
| + } |
| +} |