OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 import 'basic.dart'; | 5 import 'basic.dart'; |
6 | 6 |
7 typedef UINode Builder(Navigator navigator); | 7 typedef Widget Builder(Navigator navigator); |
8 | 8 |
9 abstract class RouteBase { | 9 abstract class RouteBase { |
10 RouteBase({this.name}); | 10 RouteBase({this.name}); |
11 final String name; | 11 final String name; |
12 UINode build(Navigator navigator); | 12 Widget build(Navigator navigator); |
13 } | 13 } |
14 | 14 |
15 class Route extends RouteBase { | 15 class Route extends RouteBase { |
16 Route({String name, this.builder}) : super(name: name); | 16 Route({String name, this.builder}) : super(name: name); |
17 final Builder builder; | 17 final Builder builder; |
18 UINode build(Navigator navigator) => builder(navigator); | 18 Widget build(Navigator navigator) => builder(navigator); |
19 } | 19 } |
20 | 20 |
21 class Navigator extends Component { | 21 class Navigator extends Component { |
22 Navigator({Object key, this.currentRoute, this.routes}) | 22 Navigator({Object key, this.currentRoute, this.routes}) |
23 : super(key: key, stateful: true); | 23 : super(key: key, stateful: true); |
24 | 24 |
25 RouteBase currentRoute; | 25 RouteBase currentRoute; |
26 List<RouteBase> routes; | 26 List<RouteBase> routes; |
27 | 27 |
28 void syncFields(Navigator source) { | 28 void syncFields(Navigator source) { |
(...skipping 13 matching lines...) Expand all Loading... |
42 } | 42 } |
43 assert(false); // route not found | 43 assert(false); // route not found |
44 } | 44 } |
45 | 45 |
46 void pushRoute(RouteBase route) { | 46 void pushRoute(RouteBase route) { |
47 setState(() { | 47 setState(() { |
48 currentRoute = route; | 48 currentRoute = route; |
49 }); | 49 }); |
50 } | 50 } |
51 | 51 |
52 UINode build() { | 52 Widget build() { |
53 Route route = currentRoute == null ? routes[0] : currentRoute; | 53 Route route = currentRoute == null ? routes[0] : currentRoute; |
54 assert(route != null); | 54 assert(route != null); |
55 return route.build(this); | 55 return route.build(this); |
56 } | 56 } |
57 } | 57 } |
OLD | NEW |