Commit fa8c4515 authored by Hixie's avatar Hixie Committed by Ian Hickson

Heroes

parent 8414b4c1
...@@ -186,14 +186,16 @@ class StockHomeState extends State<StockHome> { ...@@ -186,14 +186,16 @@ class StockHomeState extends State<StockHome> {
Widget buildStockList(BuildContext context, Iterable<Stock> stocks) { Widget buildStockList(BuildContext context, Iterable<Stock> stocks) {
return new StockList( return new StockList(
stocks: stocks.toList(), stocks: stocks.toList(),
onAction: (Stock stock, GlobalKey arrowKey) { onAction: (Stock stock, Key arrowKey) {
setState(() { setState(() {
stock.percentChange = 100.0 * (1.0 / stock.lastSale); stock.percentChange = 100.0 * (1.0 / stock.lastSale);
stock.lastSale += 1.0; stock.lastSale += 1.0;
}); });
}, },
onOpen: (Stock stock, GlobalKey arrowKey) { onOpen: (Stock stock, Key arrowKey) {
config.navigator.pushNamed('/stock/${stock.symbol}'); Set<Key> mostValuableKeys = new Set<Key>();
mostValuableKeys.add(arrowKey);
config.navigator.pushNamed('/stock/${stock.symbol}', mostValuableKeys: mostValuableKeys);
} }
); );
} }
......
...@@ -6,7 +6,7 @@ part of stocks; ...@@ -6,7 +6,7 @@ part of stocks;
enum StockRowPartKind { arrow } enum StockRowPartKind { arrow }
class StockRowPartKey extends GlobalKey { class StockRowPartKey extends Key {
const StockRowPartKey(this.stock, this.part) : super.constructor(); const StockRowPartKey(this.stock, this.part) : super.constructor();
final Stock stock; final Stock stock;
final StockRowPartKind part; final StockRowPartKind part;
...@@ -21,7 +21,7 @@ class StockRowPartKey extends GlobalKey { ...@@ -21,7 +21,7 @@ class StockRowPartKey extends GlobalKey {
String toString() => '[StockRowPartKey ${stock.symbol}:${part.toString().split(".")[1]})]'; String toString() => '[StockRowPartKey ${stock.symbol}:${part.toString().split(".")[1]})]';
} }
typedef void StockRowActionCallback(Stock stock, GlobalKey arrowKey); typedef void StockRowActionCallback(Stock stock, Key arrowKey);
class StockRow extends StatelessComponent { class StockRow extends StatelessComponent {
StockRow({ StockRow({
...@@ -30,7 +30,7 @@ class StockRow extends StatelessComponent { ...@@ -30,7 +30,7 @@ class StockRow extends StatelessComponent {
this.onLongPressed this.onLongPressed
}) : this.stock = stock, }) : this.stock = stock,
_arrowKey = new StockRowPartKey(stock, StockRowPartKind.arrow), _arrowKey = new StockRowPartKey(stock, StockRowPartKind.arrow),
super(key: new GlobalObjectKey(stock)); super(key: new ObjectKey(stock));
final Stock stock; final Stock stock;
final StockRowActionCallback onPressed; final StockRowActionCallback onPressed;
...@@ -53,7 +53,7 @@ class StockRow extends StatelessComponent { ...@@ -53,7 +53,7 @@ class StockRow extends StatelessComponent {
} }
Widget build(BuildContext context) { Widget build(BuildContext context) {
String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}"; final String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}";
String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%"; String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%";
if (stock.percentChange > 0) if (stock.percentChange > 0)
changeInPrice = "+" + changeInPrice; changeInPrice = "+" + changeInPrice;
...@@ -69,9 +69,12 @@ class StockRow extends StatelessComponent { ...@@ -69,9 +69,12 @@ class StockRow extends StatelessComponent {
), ),
child: new Row(<Widget>[ child: new Row(<Widget>[
new Container( new Container(
key: _arrowKey, margin: const EdgeDims.only(right: 5.0),
child: new StockArrow(percentChange: stock.percentChange), child: new Hero(
margin: const EdgeDims.only(right: 5.0) tag: StockRowPartKind.arrow,
key: _arrowKey,
child: new StockArrow(percentChange: stock.percentChange)
)
), ),
new Flexible( new Flexible(
child: new Row(<Widget>[ child: new Row(<Widget>[
......
...@@ -36,7 +36,11 @@ class StockSymbolViewer extends StatelessComponent { ...@@ -36,7 +36,11 @@ class StockSymbolViewer extends StatelessComponent {
'${stock.symbol}', '${stock.symbol}',
style: Theme.of(context).text.display2 style: Theme.of(context).text.display2
), ),
new StockArrow(percentChange: stock.percentChange) new Hero(
tag: StockRowPartKind.arrow,
turns: 2,
child: new StockArrow(percentChange: stock.percentChange)
),
], ],
justifyContent: FlexJustifyContent.spaceBetween justifyContent: FlexJustifyContent.spaceBetween
), ),
...@@ -51,7 +55,8 @@ class StockSymbolViewer extends StatelessComponent { ...@@ -51,7 +55,8 @@ class StockSymbolViewer extends StatelessComponent {
) )
) )
) )
]) ]
)
); );
} }
......
This diff is collapsed.
...@@ -16,6 +16,7 @@ export 'src/widgets/focus.dart'; ...@@ -16,6 +16,7 @@ export 'src/widgets/focus.dart';
export 'src/widgets/framework.dart'; export 'src/widgets/framework.dart';
export 'src/widgets/gesture_detector.dart'; export 'src/widgets/gesture_detector.dart';
export 'src/widgets/gridpaper.dart'; export 'src/widgets/gridpaper.dart';
export 'src/widgets/heroes.dart';
export 'src/widgets/homogeneous_viewport.dart'; export 'src/widgets/homogeneous_viewport.dart';
export 'src/widgets/mimic.dart'; export 'src/widgets/mimic.dart';
export 'src/widgets/mixed_viewport.dart'; export 'src/widgets/mixed_viewport.dart';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment