Adam Barth | df9d48a | 2015-03-17 15:08:53 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Adam Barth | 9d9d2d5 | 2015-03-19 11:17:48 -0700 | [diff] [blame] | 5 | import 'package:sky/framework/components/ink_well.dart'; |
Adam Barth | df9d48a | 2015-03-17 15:08:53 -0700 | [diff] [blame] | 6 | import 'package:sky/framework/fn.dart'; |
Hixie | 4c15a96 | 2015-05-15 15:16:25 -0700 | [diff] [blame] | 7 | import 'package:sky/framework/layout.dart'; |
Adam Barth | df9d48a | 2015-03-17 15:08:53 -0700 | [diff] [blame] | 8 | import 'package:sky/framework/theme/typography.dart' as typography; |
| 9 | import 'stock_arrow.dart'; |
| 10 | import 'stock_data.dart'; |
Rafael Weinstein | 202f99d | 2015-03-02 20:55:02 -0800 | [diff] [blame] | 11 | |
Adam Barth | c621700 | 2015-03-11 10:17:54 -0700 | [diff] [blame] | 12 | class StockRow extends Component { |
Adam Barth | df9d48a | 2015-03-17 15:08:53 -0700 | [diff] [blame] | 13 | static final Style _style = new Style(''' |
Rafael Weinstein | 202f99d | 2015-03-02 20:55:02 -0800 | [diff] [blame] | 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 | |
Hixie | 4c15a96 | 2015-05-15 15:16:25 -0700 | [diff] [blame] | 22 | static final FlexBoxParentData _tickerFlex = new FlexBoxParentData()..flex = 1; |
Rafael Weinstein | 202f99d | 2015-03-02 20:55:02 -0800 | [diff] [blame] | 23 | |
Adam Barth | df9d48a | 2015-03-17 15:08:53 -0700 | [diff] [blame] | 24 | static final Style _lastSaleStyle = new Style(''' |
Rafael Weinstein | 202f99d | 2015-03-02 20:55:02 -0800 | [diff] [blame] | 25 | text-align: right; |
| 26 | padding-right: 16px;''' |
| 27 | ); |
| 28 | |
Adam Barth | df9d48a | 2015-03-17 15:08:53 -0700 | [diff] [blame] | 29 | static final Style _changeStyle = new Style(''' |
Adam Barth | 74cfcc4 | 2015-03-16 20:53:26 -0700 | [diff] [blame] | 30 | ${typography.black.caption}; |
Rafael Weinstein | 202f99d | 2015-03-02 20:55:02 -0800 | [diff] [blame] | 31 | text-align: right;''' |
| 32 | ); |
| 33 | |
Adam Barth | df9d48a | 2015-03-17 15:08:53 -0700 | [diff] [blame] | 34 | Stock stock; |
| 35 | |
Rafael Weinstein | 202f99d | 2015-03-02 20:55:02 -0800 | [diff] [blame] | 36 | StockRow({Stock stock}) : super(key: stock.symbol) { |
| 37 | this.stock = stock; |
| 38 | } |
| 39 | |
Hixie | fd14a1d | 2015-04-01 09:46:28 -0700 | [diff] [blame] | 40 | UINode build() { |
Rafael Weinstein | 202f99d | 2015-03-02 20:55:02 -0800 | [diff] [blame] | 41 | String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}"; |
| 42 | |
| 43 | String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%"; |
| 44 | if (stock.percentChange > 0) |
| 45 | changeInPrice = "+" + changeInPrice; |
| 46 | |
Hixie | fd14a1d | 2015-04-01 09:46:28 -0700 | [diff] [blame] | 47 | List<UINode> children = [ |
Rafael Weinstein | 202f99d | 2015-03-02 20:55:02 -0800 | [diff] [blame] | 48 | new StockArrow( |
| 49 | percentChange: stock.percentChange |
| 50 | ), |
Hixie | 4c15a96 | 2015-05-15 15:16:25 -0700 | [diff] [blame] | 51 | new ParentDataNode( |
| 52 | new Container( |
| 53 | key: 'Ticker', |
| 54 | children: [new Text(stock.symbol)] |
| 55 | ), |
| 56 | _tickerFlex |
Rafael Weinstein | 202f99d | 2015-03-02 20:55:02 -0800 | [diff] [blame] | 57 | ), |
| 58 | new Container( |
| 59 | key: 'LastSale', |
Rafael Weinstein | 4c2f248 | 2015-03-13 14:08:24 -0700 | [diff] [blame] | 60 | style: _lastSaleStyle, |
Rafael Weinstein | 202f99d | 2015-03-02 20:55:02 -0800 | [diff] [blame] | 61 | children: [new Text(lastSale)] |
| 62 | ), |
| 63 | new Container( |
| 64 | key: 'Change', |
Rafael Weinstein | 4c2f248 | 2015-03-13 14:08:24 -0700 | [diff] [blame] | 65 | style: _changeStyle, |
Rafael Weinstein | 202f99d | 2015-03-02 20:55:02 -0800 | [diff] [blame] | 66 | children: [new Text(changeInPrice)] |
| 67 | ) |
| 68 | ]; |
| 69 | |
Adam Barth | 1718f19 | 2015-03-25 10:41:38 -0700 | [diff] [blame] | 70 | return new StyleNode(new InkWell(children: children), _style); |
Rafael Weinstein | 202f99d | 2015-03-02 20:55:02 -0800 | [diff] [blame] | 71 | } |
Rafael Weinstein | 202f99d | 2015-03-02 20:55:02 -0800 | [diff] [blame] | 72 | } |