stock_symbol_viewer.dart 3.01 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 StatelessWidget {
12
  StockSymbolView({ this.stock });
Hixie's avatar
Hixie committed
13 14 15

  final Stock stock;

16
  @override
Hixie's avatar
Hixie committed
17
  Widget build(BuildContext context) {
18 19 20 21
    String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}";
    String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%";
    if (stock.percentChange > 0)
      changeInPrice = "+" + changeInPrice;
22

23
    TextStyle headings = Theme.of(context).textTheme.body2;
24
    return new Container(
25
      padding: new EdgeInsets.all(20.0),
26 27 28 29
      child: new Column(
        children: <Widget>[
          new Row(
            children: <Widget>[
30 31
              new Text(
                '${stock.symbol}',
32
                style: Theme.of(context).textTheme.display2
33 34 35 36 37 38 39 40
              ),
              new Hero(
                key: new ObjectKey(stock),
                tag: StockRowPartKind.arrow,
                turns: 2,
                child: new StockArrow(percentChange: stock.percentChange)
              ),
            ],
41
            mainAxisAlignment: MainAxisAlignment.spaceBetween
42 43 44 45 46 47 48 49
          ),
          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}'),
50 51 52 53 54 55 56 57 58 59 60 61 62
          new Container(
            height: 8.0
          ),
          new RichText(
            text: new TextSpan(
              style: DefaultTextStyle.of(context).merge(new TextStyle(fontSize: 8.0)),
              text: 'Prices may be delayed by ',
              children: <TextSpan>[
                new TextSpan(text: 'several', style: new TextStyle(fontStyle: FontStyle.italic)),
                new TextSpan(text: ' years.'),
              ]
            )
          ),
63
        ],
64
        mainAxisAlignment: MainAxisAlignment.collapse
65
      )
66 67 68 69
    );
  }
}

70
class StockSymbolPage extends StatelessWidget {
71
  StockSymbolPage({ this.stock });
72

73
  final Stock stock;
74

75
  @override
76
  Widget build(BuildContext context) {
Hixie's avatar
Hixie committed
77
    return new Scaffold(
78 79
      appBar: new AppBar(
        title: new Text(stock.name)
Hixie's avatar
Hixie committed
80
      ),
81 82 83
      body: new Block(
        children: <Widget>[
          new Container(
84
            margin: new EdgeInsets.all(20.0),
85 86 87 88
            child: new Card(child: new StockSymbolView(stock: stock))
          )
        ]
      )
Hixie's avatar
Hixie committed
89 90
    );
  }
91 92
}

93
class StockSymbolBottomSheet extends StatelessWidget {
94 95 96
  StockSymbolBottomSheet({ this.stock });

  final Stock stock;
Hixie's avatar
Hixie committed
97

98
  @override
99 100
  Widget build(BuildContext context) {
    return new Container(
101
      padding: new EdgeInsets.all(10.0),
102 103
      decoration: new BoxDecoration(
        border: new Border(top: new BorderSide(color: Colors.black26, width: 1.0))
104 105
      ),
      child: new StockSymbolView(stock: stock)
106 107
   );
  }
Hixie's avatar
Hixie committed
108
}