stock_symbol_viewer.dart 2.32 KB
Newer Older
Hixie's avatar
Hixie committed
1 2 3 4 5 6
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of stocks;

7
class StockSymbolView extends StatelessComponent {
8
  StockSymbolView({ this.stock });
Hixie's avatar
Hixie committed
9 10 11 12

  final Stock stock;

  Widget build(BuildContext context) {
13 14 15 16
    String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}";
    String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%";
    if (stock.percentChange > 0)
      changeInPrice = "+" + changeInPrice;
17

Hixie's avatar
Hixie committed
18
    TextStyle headings = Theme.of(context).text.body2;
19 20 21 22
    return new Container(
      padding: new EdgeDims.all(20.0),
      child: new Column(<Widget>[
          new Row(<Widget>[
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
              new Text(
                '${stock.symbol}',
                style: Theme.of(context).text.display2
              ),
              new Hero(
                key: new ObjectKey(stock),
                tag: StockRowPartKind.arrow,
                turns: 2,
                child: new StockArrow(percentChange: stock.percentChange)
              ),
            ],
            justifyContent: FlexJustifyContent.spaceBetween
          ),
          new Text('Last Sale', style: headings),
          new Text('$lastSale ($changeInPrice)'),
          new Container(
            height: 8.0
          ),
          new Text('Market Cap', style: headings),
          new Text('${stock.marketCap}'),
        ],
        justifyContent: FlexJustifyContent.collapse
45
      )
46 47 48 49 50 51
    );
  }
}

class StockSymbolPage extends StatelessComponent {
  StockSymbolPage({ this.stock });
52

53
  final Stock stock;
54

55
  Widget build(BuildContext context) {
Hixie's avatar
Hixie committed
56
    return new Scaffold(
Adam Barth's avatar
Adam Barth committed
57
      toolBar: new ToolBar(
58
        center: new Text(stock.name)
Hixie's avatar
Hixie committed
59
      ),
60 61 62 63 64 65
      body: new Block(<Widget>[
        new Container(
          margin: new EdgeDims.all(20.0),
          child: new Card(child: new StockSymbolView(stock: stock))
        )
      ])
Hixie's avatar
Hixie committed
66 67
    );
  }
68 69 70 71 72 73
}

class StockSymbolBottomSheet extends StatelessComponent {
  StockSymbolBottomSheet({ this.stock });

  final Stock stock;
Hixie's avatar
Hixie committed
74

75 76 77 78 79
  Widget build(BuildContext context) {
    return new Container(
      padding: new EdgeDims.all(10.0),
      decoration: new BoxDecoration(
        border: new Border(top: new BorderSide(color: Colors.black26, width: 1.0))
80 81
      ),
      child: new StockSymbolView(stock: stock)
82 83
   );
  }
Hixie's avatar
Hixie committed
84
}