stock_symbol_viewer.dart 2.5 KB
Newer Older
Hixie's avatar
Hixie committed
1 2 3 4
// 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.

5 6 7 8 9
import 'package:flutter/material.dart';

import 'stock_data.dart';
import 'stock_arrow.dart';
import 'stock_row.dart';
Hixie's avatar
Hixie committed
10

11
class StockSymbolView extends StatelessComponent {
12
  StockSymbolView({ this.stock });
Hixie's avatar
Hixie committed
13 14 15 16

  final Stock stock;

  Widget build(BuildContext context) {
17 18 19 20
    String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}";
    String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%";
    if (stock.percentChange > 0)
      changeInPrice = "+" + changeInPrice;
21

Hixie's avatar
Hixie committed
22
    TextStyle headings = Theme.of(context).text.body2;
23 24
    return new Container(
      padding: new EdgeDims.all(20.0),
25 26 27 28
      child: new Column(
        children: <Widget>[
          new Row(
            children: <Widget>[
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
              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
51
      )
52 53 54 55 56 57
    );
  }
}

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

59
  final Stock stock;
60

61
  Widget build(BuildContext context) {
Hixie's avatar
Hixie committed
62
    return new Scaffold(
Adam Barth's avatar
Adam Barth committed
63
      toolBar: new ToolBar(
64
        center: new Text(stock.name)
Hixie's avatar
Hixie committed
65
      ),
66 67 68 69 70 71 72 73
      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
74 75
    );
  }
76 77 78 79 80 81
}

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

  final Stock stock;
Hixie's avatar
Hixie committed
82

83 84 85 86 87
  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))
88 89
      ),
      child: new StockSymbolView(stock: stock)
90 91
   );
  }
Hixie's avatar
Hixie committed
92
}