Remove the "most valuable keys" Hero feature (#5500)
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
@@ -21,12 +19,11 @@ class Photo {
|
||||
final String caption;
|
||||
|
||||
bool isFavorite;
|
||||
String get tag => assetName; // Assuming that all asset names are unique.
|
||||
|
||||
bool get isValid => assetName != null && title != null && caption != null && isFavorite != null;
|
||||
}
|
||||
|
||||
const String photoHeroTag = 'Photo';
|
||||
|
||||
typedef void BannerTapCallback(Photo photo);
|
||||
|
||||
class GridDemoPhotoItem extends StatelessWidget {
|
||||
@@ -46,21 +43,14 @@ class GridDemoPhotoItem extends StatelessWidget {
|
||||
final BannerTapCallback onBannerTap; // User taps on the photo's header or footer.
|
||||
|
||||
void showPhoto(BuildContext context) {
|
||||
Key photoKey = new Key(photo.assetName);
|
||||
Set<Key> mostValuableKeys = new HashSet<Key>();
|
||||
mostValuableKeys.add(photoKey);
|
||||
|
||||
Navigator.push(context, new MaterialPageRoute<Null>(
|
||||
settings: new RouteSettings(
|
||||
mostValuableKeys: mostValuableKeys
|
||||
),
|
||||
builder: (BuildContext context) {
|
||||
return new Scaffold(
|
||||
appBar: new AppBar(
|
||||
title: new Text(photo.title)
|
||||
),
|
||||
body: new Hero(
|
||||
tag: photoHeroTag,
|
||||
tag: photo.tag,
|
||||
child: new Image.asset(photo.assetName, fit: ImageFit.cover)
|
||||
)
|
||||
);
|
||||
@@ -74,7 +64,7 @@ class GridDemoPhotoItem extends StatelessWidget {
|
||||
onTap: () { showPhoto(context); },
|
||||
child: new Hero(
|
||||
key: new Key(photo.assetName),
|
||||
tag: photoHeroTag,
|
||||
tag: photo.tag,
|
||||
child: new Image.asset(photo.assetName, fit: ImageFit.cover)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -292,7 +292,7 @@ class ShrineHome extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ShrineHomeState extends State<ShrineHome> {
|
||||
static final GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>(debugLabel: 'Order page');
|
||||
static final GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>(debugLabel: 'Shrine Home');
|
||||
static final GlobalKey<ScrollableState> scrollableKey = new GlobalKey<ScrollableState>();
|
||||
static final GridDelegate gridDelegate = new ShrineGridDelegate();
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ class OrderPage extends StatefulWidget {
|
||||
/// arranged in two columns. Enables the user to specify a quantity and add an
|
||||
/// order to the shopping cart.
|
||||
class _OrderPageState extends State<OrderPage> {
|
||||
static final GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>(debugLabel: 'Order page');
|
||||
static final GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>(debugLabel: 'Shrine Order');
|
||||
static final GlobalKey<ScrollableState> scrollableKey = new GlobalKey<ScrollableState>();
|
||||
|
||||
Order get currentOrder => ShrineOrderRoute.of(context).order;
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart' show debugDumpRenderTree, debugDumpLayerTree, debugDumpSemanticsTree;
|
||||
import 'package:flutter/scheduler.dart' show timeDilation;
|
||||
@@ -245,7 +243,7 @@ class StockHomeState extends State<StockHome> {
|
||||
return stocks.where((Stock stock) => stock.symbol.contains(regexp));
|
||||
}
|
||||
|
||||
void _buyStock(Stock stock, Key arrowKey) {
|
||||
void _buyStock(Stock stock) {
|
||||
setState(() {
|
||||
stock.percentChange = 100.0 * (1.0 / stock.lastSale);
|
||||
stock.lastSale += 1.0;
|
||||
@@ -255,7 +253,7 @@ class StockHomeState extends State<StockHome> {
|
||||
action: new SnackBarAction(
|
||||
label: "BUY MORE",
|
||||
onPressed: () {
|
||||
_buyStock(stock, arrowKey);
|
||||
_buyStock(stock);
|
||||
}
|
||||
)
|
||||
));
|
||||
@@ -263,15 +261,12 @@ class StockHomeState extends State<StockHome> {
|
||||
|
||||
Widget _buildStockList(BuildContext context, Iterable<Stock> stocks, StockHomeTab tab) {
|
||||
return new StockList(
|
||||
keySalt: tab,
|
||||
stocks: stocks.toList(),
|
||||
onAction: _buyStock,
|
||||
onOpen: (Stock stock, Key arrowKey) {
|
||||
Set<Key> mostValuableKeys = new HashSet<Key>();
|
||||
mostValuableKeys.add(arrowKey);
|
||||
Navigator.pushNamed(context, '/stock/${stock.symbol}', mostValuableKeys: mostValuableKeys);
|
||||
onOpen: (Stock stock) {
|
||||
Navigator.pushNamed(context, '/stock/${stock.symbol}');
|
||||
},
|
||||
onShow: (Stock stock, Key arrowKey) {
|
||||
onShow: (Stock stock) {
|
||||
_scaffoldKey.currentState.showBottomSheet((BuildContext context) => new StockSymbolBottomSheet(stock: stock));
|
||||
}
|
||||
);
|
||||
|
||||
@@ -8,9 +8,8 @@ import 'stock_data.dart';
|
||||
import 'stock_row.dart';
|
||||
|
||||
class StockList extends StatelessWidget {
|
||||
StockList({ Key key, this.keySalt, this.stocks, this.onOpen, this.onShow, this.onAction }) : super(key: key);
|
||||
StockList({ Key key, this.stocks, this.onOpen, this.onShow, this.onAction }) : super(key: key);
|
||||
|
||||
final Object keySalt;
|
||||
final List<Stock> stocks;
|
||||
final StockRowActionCallback onOpen;
|
||||
final StockRowActionCallback onShow;
|
||||
@@ -23,7 +22,6 @@ class StockList extends StatelessWidget {
|
||||
itemExtent: StockRow.kHeight,
|
||||
children: stocks.map((Stock stock) {
|
||||
return new StockRow(
|
||||
keySalt: keySalt,
|
||||
stock: stock,
|
||||
onPressed: onOpen,
|
||||
onDoubleTap: onShow,
|
||||
|
||||
@@ -7,58 +7,25 @@ import 'package:flutter/material.dart';
|
||||
import 'stock_data.dart';
|
||||
import 'stock_arrow.dart';
|
||||
|
||||
enum StockRowPartKind { arrow }
|
||||
|
||||
class StockRowPartKey extends LocalKey {
|
||||
const StockRowPartKey(this.keySalt, this.stock, this.part);
|
||||
|
||||
final Object keySalt;
|
||||
final Stock stock;
|
||||
final StockRowPartKind part;
|
||||
|
||||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
if (identical(this, other))
|
||||
return true;
|
||||
if (other.runtimeType != runtimeType)
|
||||
return false;
|
||||
final StockRowPartKey typedOther = other;
|
||||
return keySalt == typedOther.keySalt
|
||||
&& stock == typedOther.stock
|
||||
&& part == typedOther.part;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => hashValues(keySalt, stock, part);
|
||||
|
||||
@override
|
||||
String toString() => '[$runtimeType ${keySalt.toString().split(".")[1]}:${stock.symbol}:${part.toString().split(".")[1]}]';
|
||||
}
|
||||
|
||||
typedef void StockRowActionCallback(Stock stock, Key arrowKey);
|
||||
typedef void StockRowActionCallback(Stock stock);
|
||||
|
||||
class StockRow extends StatelessWidget {
|
||||
StockRow({
|
||||
Stock stock,
|
||||
Object keySalt,
|
||||
this.onPressed,
|
||||
this.onDoubleTap,
|
||||
this.onLongPressed
|
||||
}) : this.stock = stock,
|
||||
_arrowKey = new StockRowPartKey(keySalt, stock, StockRowPartKind.arrow),
|
||||
super(key: new ObjectKey(stock));
|
||||
}) : this.stock = stock, super(key: new ObjectKey(stock));
|
||||
|
||||
final Stock stock;
|
||||
final StockRowActionCallback onPressed;
|
||||
final StockRowActionCallback onDoubleTap;
|
||||
final StockRowActionCallback onLongPressed;
|
||||
|
||||
final Key _arrowKey;
|
||||
|
||||
static const double kHeight = 79.0;
|
||||
|
||||
GestureTapCallback _getHandler(StockRowActionCallback callback) {
|
||||
return callback == null ? null : () => callback(stock, _arrowKey);
|
||||
return callback == null ? null : () => callback(stock);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -83,8 +50,7 @@ class StockRow extends StatelessWidget {
|
||||
new Container(
|
||||
margin: const EdgeInsets.only(right: 5.0),
|
||||
child: new Hero(
|
||||
tag: StockRowPartKind.arrow,
|
||||
key: _arrowKey,
|
||||
tag: stock,
|
||||
child: new StockArrow(percentChange: stock.percentChange)
|
||||
)
|
||||
),
|
||||
|
||||
@@ -6,12 +6,12 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'stock_data.dart';
|
||||
import 'stock_arrow.dart';
|
||||
import 'stock_row.dart';
|
||||
|
||||
class StockSymbolView extends StatelessWidget {
|
||||
StockSymbolView({ this.stock });
|
||||
class _StockSymbolView extends StatelessWidget {
|
||||
_StockSymbolView({ this.stock, this.arrow });
|
||||
|
||||
final Stock stock;
|
||||
final Widget arrow;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -31,12 +31,7 @@ class StockSymbolView extends StatelessWidget {
|
||||
'${stock.symbol}',
|
||||
style: Theme.of(context).textTheme.display2
|
||||
),
|
||||
new Hero(
|
||||
key: new ObjectKey(stock),
|
||||
tag: StockRowPartKind.arrow,
|
||||
turns: 2,
|
||||
child: new StockArrow(percentChange: stock.percentChange)
|
||||
),
|
||||
arrow,
|
||||
],
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween
|
||||
),
|
||||
@@ -82,7 +77,16 @@ class StockSymbolPage extends StatelessWidget {
|
||||
children: <Widget>[
|
||||
new Container(
|
||||
margin: new EdgeInsets.all(20.0),
|
||||
child: new Card(child: new StockSymbolView(stock: stock))
|
||||
child: new Card(
|
||||
child: new _StockSymbolView(
|
||||
stock: stock,
|
||||
arrow: new Hero(
|
||||
tag: stock,
|
||||
turns: 2,
|
||||
child: new StockArrow(percentChange: stock.percentChange)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -102,7 +106,10 @@ class StockSymbolBottomSheet extends StatelessWidget {
|
||||
decoration: new BoxDecoration(
|
||||
border: new Border(top: new BorderSide(color: Colors.black26))
|
||||
),
|
||||
child: new StockSymbolView(stock: stock)
|
||||
child: new _StockSymbolView(
|
||||
stock: stock,
|
||||
arrow: new StockArrow(percentChange: stock.percentChange)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user