Let MaterialApp.onGenerateRoute return a Route

Also:
 - minor code reindents in places.
 - reset the widget tree between tests.
 - once you generate a route, don't let its builder change
   (previously it would keep changing as the routes table changed).
 - revert the stocks app toolbar-fading-on-forward-transition thing.
This commit is contained in:
Hixie
2015-12-03 12:41:48 -08:00
parent 884b2cf56a
commit df07a69b12
10 changed files with 64 additions and 103 deletions

View File

@@ -8,7 +8,6 @@ import 'dart:async';
import 'dart:math' as math;
import 'dart:ui' as ui;
import 'package:flutter/animation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
@@ -74,16 +73,19 @@ class StocksAppState extends State<StocksApp> {
}
}
RouteBuilder _getRoute(String name) {
List<String> path = name.split('/');
Route _getRoute(NamedRouteSettings settings) {
List<String> path = settings.name.split('/');
if (path[0] != '')
return null;
if (path[1] == 'stock') {
if (path.length != 3)
return null;
if (_stocks.containsKey(path[2]))
return (RouteArguments args) => new StockSymbolPage(stock: _stocks[path[2]]);
return null;
if (_stocks.containsKey(path[2])) {
return new MaterialPageRoute(
settings: settings,
builder: (BuildContext context) => new StockSymbolPage(stock: _stocks[path[2]])
);
}
}
return null;
}

View File

@@ -145,22 +145,13 @@ class StockHomeState extends State<StockHome> {
}
Widget buildToolBar() {
PageRoute page = ModalRoute.of(context);
return new ToolBar(
elevation: 0,
left: new IconButton(
icon: "navigation/menu",
onPressed: () => _scaffoldKey.currentState?.openDrawer()
),
center: new FadeTransition(
opacity: new AnimatedValue<double>(
1.0,
end: 0.0,
curve: const Interval(0.0, 0.5)
),
performance: page.forwardPerformance,
child: new Text('Stocks')
),
center: new Text('Stocks'),
right: <Widget>[
new IconButton(
icon: "action/search",

View File

@@ -5,7 +5,7 @@
part of stocks;
class StockSymbolView extends StatelessComponent {
StockSymbolView({ this.stock});
StockSymbolView({ this.stock });
final Stock stock;
@@ -20,28 +20,28 @@ class StockSymbolView extends StatelessComponent {
padding: new EdgeDims.all(20.0),
child: new Column(<Widget>[
new Row(<Widget>[
new Text(
'${stock.symbol}',
style: Theme.of(context).text.display2
),
new Hero(
key: new ObjectKey(stock),
tag: StockRowPartKind.arrow,
turns: 2,
child: new StockArrow(percentChange: stock.percentChange)
),
],
justifyContent: FlexJustifyContent.spaceBetween
),
new Text('Last Sale', style: headings),
new Text('$lastSale ($changeInPrice)'),
new Container(
height: 8.0
),
new Text('Market Cap', style: headings),
new Text('${stock.marketCap}'),
],
justifyContent: FlexJustifyContent.collapse
new Text(
'${stock.symbol}',
style: Theme.of(context).text.display2
),
new Hero(
key: new ObjectKey(stock),
tag: StockRowPartKind.arrow,
turns: 2,
child: new StockArrow(percentChange: stock.percentChange)
),
],
justifyContent: FlexJustifyContent.spaceBetween
),
new Text('Last Sale', style: headings),
new Text('$lastSale ($changeInPrice)'),
new Container(
height: 8.0
),
new Text('Market Cap', style: headings),
new Text('${stock.marketCap}'),
],
justifyContent: FlexJustifyContent.collapse
)
);
}
@@ -53,7 +53,6 @@ class StockSymbolPage extends StatelessComponent {
final Stock stock;
Widget build(BuildContext context) {
PageRoute page = ModalRoute.of(context);
return new Scaffold(
toolBar: new ToolBar(
left: new IconButton(
@@ -62,15 +61,7 @@ class StockSymbolPage extends StatelessComponent {
Navigator.pop(context);
}
),
center: new FadeTransition(
opacity: new AnimatedValue<double>(
0.0,
end: 1.0,
curve: const Interval(0.5, 1.0)
),
performance: page.performance,
child: new Text(stock.name)
)
center: new Text(stock.name)
),
body: new Block(<Widget>[
new Container(