Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: sky/sdk/lib/widgets/navigator.dart

Issue 1231753008: Support for anonymous state routes (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: re-upload Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/sdk/lib/widgets/drawer.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'package:sky/widgets/basic.dart'; 5 import 'package:sky/widgets/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.key });
11 final String name; 11 final Object key;
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(key: name);
18 String get name => key;
18 final Builder builder; 19 final Builder builder;
19 Widget build(Navigator navigator, RouteBase route) => builder(navigator, route ); 20 Widget build(Navigator navigator, RouteBase route) => builder(navigator, route );
20 } 21 }
21 22
22 class RouteState extends RouteBase { 23 class RouteState extends RouteBase {
23 24
24 RouteState({this.callback, this.route, String name}) : super(name: name); 25 RouteState({ this.callback, this.route, Object key }) : super(key: key);
25 26
26 RouteBase route; 27 RouteBase route;
27 Function callback; 28 Function callback;
28 29
29 Widget build(Navigator navigator, _) => route.build(navigator, this); 30 Widget build(Navigator navigator, _) => route.build(navigator, this);
30 31
31 void popState() { 32 void popState() {
32 if (callback != null) 33 if (callback != null)
33 callback(this); 34 callback(this);
34 } 35 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 Navigator(this.state, { String key }) : super(key: key); 80 Navigator(this.state, { String key }) : super(key: key);
80 81
81 NavigationState state; 82 NavigationState state;
82 83
83 void syncFields(Navigator source) { 84 void syncFields(Navigator source) {
84 state = source.state; 85 state = source.state;
85 } 86 }
86 87
87 RouteBase get currentRoute => state.currentRoute; 88 RouteBase get currentRoute => state.currentRoute;
88 89
89 void pushState(String name, Function callback) { 90 void pushState(Object key, Function callback) {
90 RouteBase route = new RouteState( 91 RouteBase route = new RouteState(
91 name: name, 92 key: key,
92 callback: callback, 93 callback: callback,
93 route: state.currentRoute 94 route: state.currentRoute
94 ); 95 );
95 push(route); 96 push(route);
96 } 97 }
97 98
98 void pushNamed(String name) { 99 void pushNamed(String name) {
99 setState(() { 100 setState(() {
100 state.pushNamed(name); 101 state.pushNamed(name);
101 }); 102 });
102 } 103 }
103 104
104 void push(RouteBase route) { 105 void push(RouteBase route) {
105 setState(() { 106 setState(() {
106 state.push(route); 107 state.push(route);
107 }); 108 });
108 } 109 }
109 110
110 void pop() { 111 void pop() {
111 setState(() { 112 setState(() {
112 state.pop(); 113 state.pop();
113 }); 114 });
114 } 115 }
115 116
116 Widget build() { 117 Widget build() {
117 return state.currentRoute.build(this, state.currentRoute); 118 return state.currentRoute.build(this, state.currentRoute);
118 } 119 }
119 } 120 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/widgets/drawer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698