stock_symbol_viewer.dart 2.4 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
    return new Container(
      padding: new EdgeDims.all(20.0),
21 22 23 24
      child: new Column(
        children: <Widget>[
          new Row(
            children: <Widget>[
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
              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
47
      )
48 49 50 51 52 53
    );
  }
}

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

55
  final Stock stock;
56

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

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

  final Stock stock;
Hixie's avatar
Hixie committed
78

79 80 81 82 83
  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))
84 85
      ),
      child: new StockSymbolView(stock: stock)
86 87
   );
  }
Hixie's avatar
Hixie committed
88
}