flutter/examples/stocks/lib/stock_symbol_viewer.dart
Ian Hickson a94999ba50 Clean up imports and exports.
Each layer is supposed to reexport the parts of the previous layer
that are part of its API.

- In painting.dart, export from dart:ui all the Canvas-related APIs
  that make sense to be used at higher levels, e.g. PaintingStyle.

- Delete painting/shadows.dart. It was dead code.

- In rendering/object.dart, export all of painting.dart.

- In widgets/basic.dart, export all of painting.dart and
  animation.dart. Some classes in animation/ are renamed to make this
  less disruptive and confusing to the namespace.

- Split out Stocks back into an import model rather than a part model,
  so that it's easier to manage its dependencies on a per-file basis.

- Move Ticker to scheduler library.

- Remove as many redundant imports as possible now.

- Some minor nit picking cleanup in various files.
2016-02-11 00:06:23 -08:00

93 lines
2.5 KiB
Dart

// 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.
import 'package:flutter/material.dart';
import 'stock_data.dart';
import 'stock_arrow.dart';
import 'stock_row.dart';
class StockSymbolView extends StatelessComponent {
StockSymbolView({ this.stock });
final Stock stock;
Widget build(BuildContext context) {
String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}";
String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%";
if (stock.percentChange > 0)
changeInPrice = "+" + changeInPrice;
TextStyle headings = Theme.of(context).text.body2;
return new Container(
padding: new EdgeDims.all(20.0),
child: new Column(
children: <Widget>[
new Row(
children: <Widget>[
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
)
);
}
}
class StockSymbolPage extends StatelessComponent {
StockSymbolPage({ this.stock });
final Stock stock;
Widget build(BuildContext context) {
return new Scaffold(
toolBar: new ToolBar(
center: new Text(stock.name)
),
body: new Block(
children: <Widget>[
new Container(
margin: new EdgeDims.all(20.0),
child: new Card(child: new StockSymbolView(stock: stock))
)
]
)
);
}
}
class StockSymbolBottomSheet extends StatelessComponent {
StockSymbolBottomSheet({ this.stock });
final Stock stock;
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))
),
child: new StockSymbolView(stock: stock)
);
}
}