Add arguments for pushing named routes (#27058)

This commit is contained in:
Michael Goderbauer
2019-01-29 21:35:21 -08:00
committed by GitHub
parent f365217e6a
commit e7d6348826
5 changed files with 306 additions and 45 deletions

View File

@@ -84,22 +84,8 @@ class StocksAppState extends State<StocksApp> {
}
Route<dynamic> _getRoute(RouteSettings settings) {
// Routes, by convention, are split on slashes, like filesystem paths.
final List<String> path = settings.name.split('/');
// We only support paths that start with a slash, so bail if
// the first component is not empty:
if (path[0] != '')
return null;
// If the path is "/stock:..." then show a stock page for the
// specified stock symbol.
if (path[1].startsWith('stock:')) {
// We don't yet support subpages of a stock, so bail if there's
// any more path components.
if (path.length != 2)
return null;
// Extract the symbol part of "stock:..." and return a route
// for that symbol.
final String symbol = path[1].substring(6);
if (settings.name == '/stocks') {
final String symbol = settings.arguments;
return MaterialPageRoute<void>(
settings: settings,
builder: (BuildContext context) => StockSymbolPage(symbol: symbol, stocks: stocks),

View File

@@ -262,7 +262,7 @@ class StockHomeState extends State<StockHome> {
stocks: stocks.toList(),
onAction: _buyStock,
onOpen: (Stock stock) {
Navigator.pushNamed(context, '/stock:${stock.symbol}');
Navigator.pushNamed(context, '/stock', arguments: stock.symbol);
},
onShow: (Stock stock) {
_scaffoldKey.currentState.showBottomSheet<void>((BuildContext context) => StockSymbolBottomSheet(stock: stock));