Commit b76af41f authored by Adam Barth's avatar Adam Barth

Prepare StockList for use in stocks2

This CL does a bunch of ground work for getting StockList ready for use in
stocks2. It's still not quite working because of an interaction with Scaffold
that we don't fully understand.

R=eseidel@chromium.org, ianh@google.com

Review URL: https://codereview.chromium.org/1148793005
parent b05d618e
...@@ -20,7 +20,7 @@ import 'package:sky/framework/theme2/typography.dart' as typography; ...@@ -20,7 +20,7 @@ import 'package:sky/framework/theme2/typography.dart' as typography;
import 'package:sky/framework/theme2/colors.dart' as colors; import 'package:sky/framework/theme2/colors.dart' as colors;
import 'stock_data.dart'; import 'stock_data.dart';
import 'package:sky/framework/rendering/box.dart'; import 'package:sky/framework/rendering/box.dart';
// import 'stock_list.dart'; import 'stock_list.dart';
// import 'stock_menu.dart'; // import 'stock_menu.dart';
import 'dart:async'; import 'dart:async';
......
...@@ -55,11 +55,11 @@ class StockDataFetcher { ...@@ -55,11 +55,11 @@ class StockDataFetcher {
final StockDataCallback callback; final StockDataCallback callback;
StockDataFetcher(this.callback) { StockDataFetcher(this.callback) {
// _fetchNextChunk(); // TODO(ianh): crashes _fetchNextChunk();
} }
void _fetchNextChunk() { void _fetchNextChunk() {
fetch('data/stock_data_${_currentChunk++}.json').then((Response response) { fetch('../data/stock_data_${_currentChunk++}.json').then((Response response) {
String json = response.bodyAsString(); String json = response.bodyAsString();
JsonDecoder decoder = new JsonDecoder(); JsonDecoder decoder = new JsonDecoder();
......
...@@ -15,7 +15,7 @@ class Stocklist extends FixedHeightScrollable { ...@@ -15,7 +15,7 @@ class Stocklist extends FixedHeightScrollable {
Object key, Object key,
this.stocks, this.stocks,
this.query this.query
}) : super(key: key); }) : super(itemHeight: StockRow.kHeight, key: key);
List<UINode> buildItems(int start, int count) { List<UINode> buildItems(int start, int count) {
var filteredStocks = stocks.where((stock) { var filteredStocks = stocks.where((stock) {
......
...@@ -2,70 +2,81 @@ ...@@ -2,70 +2,81 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:sky' as sky;
import 'package:sky/framework/components2/ink_well.dart'; import 'package:sky/framework/components2/ink_well.dart';
import 'package:sky/framework/fn2.dart'; import 'package:sky/framework/fn2.dart';
import 'package:sky/framework/rendering/box.dart';
import 'package:sky/framework/theme/typography.dart' as typography; import 'package:sky/framework/theme/typography.dart' as typography;
import 'stock_arrow.dart'; import 'stock_arrow.dart';
import 'stock_data.dart'; import 'stock_data.dart';
class StockRow extends Component { class StockRow extends Component {
static final Style _style = new Style(''' static const double kHeight = 100.0;
align-items: center; // static final Style _style = new Style('''
border-bottom: 1px solid #F4F4F4; // align-items: center;
padding-top: 16px; // border-bottom: 1px solid #F4F4F4;
padding-left: 16px; // padding-top: 16px;
padding-right: 16px; // padding-left: 16px;
padding-bottom: 20px;''' // padding-right: 16px;
); // padding-bottom: 20px;'''
// );
static final FlexBoxParentData _tickerFlex = new FlexBoxParentData()..flex = 1; // static final FlexBoxParentData _tickerFlex = new FlexBoxParentData()..flex = 1;
static final Style _lastSaleStyle = new Style(''' // static final Style _lastSaleStyle = new Style('''
text-align: right; // text-align: right;
padding-right: 16px;''' // padding-right: 16px;'''
); // );
static final Style _changeStyle = new Style(''' // static final Style _changeStyle = new Style('''
${typography.black.caption}; // ${typography.black.caption};
text-align: right;''' // text-align: right;'''
); // );
Stock stock; Stock stock;
StockRow({Stock stock}) : super(key: stock.symbol) { StockRow({ Stock stock }) : super(key: stock.symbol) {
this.stock = stock; this.stock = stock;
} }
UINode build() { UINode build() {
String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}"; // String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}";
String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%"; // String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%";
if (stock.percentChange > 0) // if (stock.percentChange > 0)
changeInPrice = "+" + changeInPrice; // changeInPrice = "+" + changeInPrice;
List<UINode> children = [ // List<UINode> children = [
new StockArrow( // new StockArrow(
percentChange: stock.percentChange // percentChange: stock.percentChange
), // ),
new ParentDataNode( // new ParentDataNode(
new Container( // new Container(
key: 'Ticker', // key: 'Ticker',
children: [new Text(stock.symbol)] // children: [new Text(stock.symbol)]
), // ),
_tickerFlex // _tickerFlex
), // ),
new Container( // new Container(
key: 'LastSale', // key: 'LastSale',
style: _lastSaleStyle, // style: _lastSaleStyle,
children: [new Text(lastSale)] // children: [new Text(lastSale)]
), // ),
new Container( // new Container(
key: 'Change', // key: 'Change',
style: _changeStyle, // style: _changeStyle,
children: [new Text(changeInPrice)] // children: [new Text(changeInPrice)]
) // )
]; // ];
return new StyleNode(new InkWell(children: children), _style); // return new StyleNode(new InkWell(children: children), _style);
return new Container(
desiredSize: const sky.Size.fromHeight(kHeight),
decoration: const BoxDecoration(
backgroundColor: const sky.Color(0xFFFFFFFF),
border: const Border(
bottom: const BorderSide(
color: const sky.Color(0xFFF4F4F4),
width: 1.0))));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment