Simplify the usage of Navigator's routes argument

(These are changes cherry-picked from in-flight branches since they are
more independent and could be helpful even without those changes.)

- Change RouteBuilder's signature to take a single argument in which the
  other fields are placed, so that we can keep iterating on those
  arguments without having to break compatibility each time. Also, this
  makes defining route builders much simpler (only one argument to
  ignore rather than a variable number).

- Expose the next performance to RouteBuilders, since sometimes the
  route itself might not be where it's used.

- Allow BuildContext to be used to walk children, just like it can for
  ancestors

- Allow BuildContext to be used to get the Widget of the current
  BuildContext

- Allow StatefulComponentElement to be referenced with a type
  specialisation so that you don't have to cast when you know what the
  type you're dealing with actually is.
This commit is contained in:
Hixie
2015-10-02 15:07:35 -07:00
parent 3fb3ec5a43
commit 90a0f6300f
19 changed files with 94 additions and 86 deletions

View File

@@ -357,7 +357,7 @@ void main() {
accentColor: Colors.redAccent[200]
),
routes: {
'/': (NavigatorState navigator, Route route) => new CardCollection(navigator: navigator),
'/': (RouteArguments args) => new CardCollection(navigator: args.navigator),
}
));
}

View File

@@ -133,7 +133,7 @@ void main() {
runApp(new App(
title: 'Drag and Drop Flutter Demo',
routes: {
'/': (NavigatorState navigator, Route route) => new DragAndDropApp(navigator: navigator)
'/': (RouteArguments args) => new DragAndDropApp(navigator: args.navigator)
}
));
}

View File

@@ -6,46 +6,46 @@ import 'package:sky/material.dart';
import 'package:sky/widgets.dart';
final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
'/': (NavigatorState navigator, Route route) => new Container(
'/': (RouteArguments args) => new Container(
padding: const EdgeDims.all(30.0),
decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)),
child: new Column([
new Text("You are at home"),
new RaisedButton(
child: new Text('GO SHOPPING'),
onPressed: () => navigator.pushNamed('/shopping')
onPressed: () => args.navigator.pushNamed('/shopping')
),
new RaisedButton(
child: new Text('START ADVENTURE'),
onPressed: () => navigator.pushNamed('/adventure')
onPressed: () => args.navigator.pushNamed('/adventure')
)],
justifyContent: FlexJustifyContent.center
)
),
'/shopping': (NavigatorState navigator, Route route) => new Container(
'/shopping': (RouteArguments args) => new Container(
padding: const EdgeDims.all(20.0),
decoration: new BoxDecoration(backgroundColor: const Color(0xFFBF5FFF)),
child: new Column([
new Text("Village Shop"),
new RaisedButton(
child: new Text('RETURN HOME'),
onPressed: () => navigator.pop()
onPressed: () => args.navigator.pop()
),
new RaisedButton(
child: new Text('GO TO DUNGEON'),
onPressed: () => navigator.pushNamed('/adventure')
onPressed: () => args.navigator.pushNamed('/adventure')
)],
justifyContent: FlexJustifyContent.center
)
),
'/adventure': (NavigatorState navigator, Route route) => new Container(
'/adventure': (RouteArguments args) => new Container(
padding: const EdgeDims.all(20.0),
decoration: new BoxDecoration(backgroundColor: const Color(0xFFDC143C)),
child: new Column([
new Text("Monster's Lair"),
new RaisedButton(
child: new Text('RUN!!!'),
onPressed: () => navigator.pop()
onPressed: () => args.navigator.pop()
)],
justifyContent: FlexJustifyContent.center
)

View File

@@ -165,7 +165,7 @@ void main() {
),
title: 'Cards',
routes: {
'/': (navigator, route) => new OverlayGeometryApp()
'/': (RouteArguments args) => new OverlayGeometryApp()
}
));
}

View File

@@ -165,7 +165,7 @@ void main() {
accentColor: Colors.redAccent[200]
),
routes: {
'/': (NavigatorState navigator, Route route) => new PageableListApp(navigator: navigator),
'/': (RouteArguments args) => new PageableListApp(navigator: args.navigator),
}
));
}