| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'package:sky/framework/components/ink_well.dart'; | 5 import 'package:sky/painting/text_style.dart'; |
| 6 import 'package:sky/framework/fn.dart'; | 6 import 'package:sky/rendering/box.dart'; |
| 7 import 'package:sky/framework/layout.dart'; | 7 import 'package:sky/widgets/ink_well.dart'; |
| 8 import 'package:sky/framework/theme/typography.dart' as typography; | 8 import 'package:sky/widgets/basic.dart'; |
| 9 import 'package:sky/widgets/theme.dart'; |
| 10 |
| 9 import 'stock_arrow.dart'; | 11 import 'stock_arrow.dart'; |
| 10 import 'stock_data.dart'; | 12 import 'stock_data.dart'; |
| 11 | 13 |
| 12 class StockRow extends Component { | 14 class StockRow extends Component { |
| 13 static final Style _style = new Style(''' | |
| 14 align-items: center; | |
| 15 border-bottom: 1px solid #F4F4F4; | |
| 16 padding-top: 16px; | |
| 17 padding-left: 16px; | |
| 18 padding-right: 16px; | |
| 19 padding-bottom: 20px;''' | |
| 20 ); | |
| 21 | 15 |
| 22 static final FlexBoxParentData _tickerFlex = new FlexBoxParentData()..flex = 1
; | 16 StockRow({ Stock stock }) : this.stock = stock, super(key: stock.symbol); |
| 23 | 17 |
| 24 static final Style _lastSaleStyle = new Style(''' | 18 final Stock stock; |
| 25 text-align: right; | |
| 26 padding-right: 16px;''' | |
| 27 ); | |
| 28 | 19 |
| 29 static final Style _changeStyle = new Style(''' | 20 static const double kHeight = 79.0; |
| 30 ${typography.black.caption}; | |
| 31 text-align: right;''' | |
| 32 ); | |
| 33 | 21 |
| 34 Stock stock; | 22 Widget build() { |
| 35 | |
| 36 StockRow({Stock stock}) : super(key: stock.symbol) { | |
| 37 this.stock = stock; | |
| 38 } | |
| 39 | |
| 40 UINode build() { | |
| 41 String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}"; | 23 String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}"; |
| 42 | 24 |
| 43 String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%"; | 25 String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%"; |
| 44 if (stock.percentChange > 0) | 26 if (stock.percentChange > 0) changeInPrice = "+" + changeInPrice; |
| 45 changeInPrice = "+" + changeInPrice; | |
| 46 | 27 |
| 47 List<UINode> children = [ | 28 List<Widget> children = [ |
| 48 new StockArrow( | 29 new Container( |
| 49 percentChange: stock.percentChange | 30 child: new StockArrow(percentChange: stock.percentChange), |
| 31 margin: const EdgeDims.only(right: 5.0) |
| 50 ), | 32 ), |
| 51 new ParentDataNode( | 33 new Flexible( |
| 52 new Container( | 34 child: new Text(stock.symbol), |
| 53 key: 'Ticker', | 35 flex: 2 |
| 54 children: [new Text(stock.symbol)] | |
| 55 ), | |
| 56 _tickerFlex | |
| 57 ), | 36 ), |
| 58 new Container( | 37 new Flexible( |
| 59 key: 'LastSale', | 38 child: new Text( |
| 60 style: _lastSaleStyle, | 39 lastSale, |
| 61 children: [new Text(lastSale)] | 40 style: const TextStyle(textAlign: TextAlign.right) |
| 41 ) |
| 62 ), | 42 ), |
| 63 new Container( | 43 new Flexible( |
| 64 key: 'Change', | 44 child: new Text( |
| 65 style: _changeStyle, | 45 changeInPrice, |
| 66 children: [new Text(changeInPrice)] | 46 style: Theme.of(this).text.caption.copyWith(textAlign: TextAlign.right
) |
| 47 ) |
| 67 ) | 48 ) |
| 68 ]; | 49 ]; |
| 69 | 50 |
| 70 return new StyleNode(new InkWell(children: children), _style); | 51 // TODO(hansmuller): An explicit |height| shouldn't be needed |
| 52 return new InkWell( |
| 53 child: new Container( |
| 54 padding: const EdgeDims(16.0, 16.0, 20.0, 16.0), |
| 55 height: kHeight, |
| 56 decoration: const BoxDecoration( |
| 57 border: const Border( |
| 58 bottom: const BorderSide(color: const Color(0xFFF4F4F4)))), |
| 59 child: new Flex(children) |
| 60 ) |
| 61 ); |
| 71 } | 62 } |
| 72 } | 63 } |
| OLD | NEW |