| 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 Widget Builder(Navigator navigator, RouteBase route); | 7 typedef Widget Builder(Navigator navigator, RouteBase route); |
| 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 Widget build(Navigator navigator, RouteBase route); | 12 Widget build(Navigator navigator, RouteBase route); |
| 13 void popState() { } | 13 void popState() { } |
| 14 } | 14 } |
| 15 | 15 |
| 16 class Route extends RouteBase { | 16 class Route extends RouteBase { |
| 17 Route({ String name, this.builder }) : super(name: name); | 17 Route({ String name, this.builder }) : super(name: name); |
| 18 final Builder builder; | 18 final Builder builder; |
| 19 |
| 20 @override |
| 19 Widget build(Navigator navigator, RouteBase route) => builder(navigator, route
); | 21 Widget build(Navigator navigator, RouteBase route) => builder(navigator, route
); |
| 20 } | 22 } |
| 21 | 23 |
| 22 class RouteState extends RouteBase { | 24 class RouteState extends RouteBase { |
| 23 | 25 |
| 24 RouteState({this.callback, this.route, String name}) : super(name: name); | 26 RouteState({this.callback, this.route, String name}) : super(name: name); |
| 25 | 27 |
| 26 RouteBase route; | 28 RouteBase route; |
| 27 Function callback; | 29 Function callback; |
| 28 | 30 |
| 31 @override |
| 29 Widget build(Navigator navigator, _) => route.build(navigator, this); | 32 Widget build(Navigator navigator, _) => route.build(navigator, this); |
| 30 | 33 |
| 34 @override |
| 31 void popState() { | 35 void popState() { |
| 32 if (callback != null) | 36 if (callback != null) |
| 33 callback(this); | 37 callback(this); |
| 34 } | 38 } |
| 35 } | 39 } |
| 36 | 40 |
| 37 class NavigationState { | 41 class NavigationState { |
| 38 | 42 |
| 39 NavigationState(List<Route> routes) { | 43 NavigationState(List<Route> routes) { |
| 40 for (Route route in routes) { | 44 for (Route route in routes) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 77 } |
| 74 } | 78 } |
| 75 } | 79 } |
| 76 | 80 |
| 77 class Navigator extends StatefulComponent { | 81 class Navigator extends StatefulComponent { |
| 78 | 82 |
| 79 Navigator(this.state, { String key }) : super(key: key); | 83 Navigator(this.state, { String key }) : super(key: key); |
| 80 | 84 |
| 81 NavigationState state; | 85 NavigationState state; |
| 82 | 86 |
| 87 @override |
| 83 void syncFields(Navigator source) { | 88 void syncFields(Navigator source) { |
| 84 state = source.state; | 89 state = source.state; |
| 85 } | 90 } |
| 86 | 91 |
| 87 RouteBase get currentRoute => state.currentRoute; | 92 RouteBase get currentRoute => state.currentRoute; |
| 88 | 93 |
| 89 void pushState(String name, Function callback) { | 94 void pushState(String name, Function callback) { |
| 90 RouteBase route = new RouteState( | 95 RouteBase route = new RouteState( |
| 91 name: name, | 96 name: name, |
| 92 callback: callback, | 97 callback: callback, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 106 state.push(route); | 111 state.push(route); |
| 107 }); | 112 }); |
| 108 } | 113 } |
| 109 | 114 |
| 110 void pop() { | 115 void pop() { |
| 111 setState(() { | 116 setState(() { |
| 112 state.pop(); | 117 state.pop(); |
| 113 }); | 118 }); |
| 114 } | 119 } |
| 115 | 120 |
| 121 @override |
| 116 Widget build() { | 122 Widget build() { |
| 117 return state.currentRoute.build(this, state.currentRoute); | 123 return state.currentRoute.build(this, state.currentRoute); |
| 118 } | 124 } |
| 119 } | 125 } |
| OLD | NEW |