Chromium Code Reviews| Index: sky/sdk/example/stocks/lib/stock_list.dart |
| diff --git a/sky/sdk/example/stocks/lib/stock_list.dart b/sky/sdk/example/stocks/lib/stock_list.dart |
| index 4b36783d186d25f5a0cd5920b5794a8a234cc844..38255540c760ed9ea070f1dc60ed226d93799a7c 100644 |
| --- a/sky/sdk/example/stocks/lib/stock_list.dart |
| +++ b/sky/sdk/example/stocks/lib/stock_list.dart |
| @@ -12,25 +12,31 @@ class Stocklist extends FixedHeightScrollable { |
| Stocklist({ |
| String key, |
| - this.stocks, |
| + List<Stock> stocks, |
| this.query |
|
Hixie
2015/07/07 15:25:13
do we still need to remember the query?
abarth-chromium
2015/07/07 15:26:21
Nope!
|
| - }) : super(itemHeight: StockRow.kHeight, key: key); |
| + }) : super(itemHeight: StockRow.kHeight, key: key) { |
| + if (query == null) { |
| + filteredStocks = stocks; |
| + } else { |
| + RegExp regexp = new RegExp(query, caseSensitive: false); |
| + filteredStocks = stocks |
| + .where((stock) => stock.symbol.contains(regexp)) |
| + .toList(growable: false); |
| + } |
| + } |
| String query; |
| - List<Stock> stocks; |
| + List<Stock> filteredStocks; |
| + |
| + int get itemCount => filteredStocks.length; |
| void syncFields(Stocklist source) { |
| query = source.query; |
| - stocks = source.stocks; |
| + filteredStocks = source.filteredStocks; |
| super.syncFields(source); |
| } |
| List<Widget> buildItems(int start, int count) { |
| - var filteredStocks = stocks.where((stock) { |
| - return query == null || |
| - stock.symbol.contains(new RegExp(query, caseSensitive: false)); |
| - }); |
| - itemCount = filteredStocks.length; |
| return filteredStocks |
| .skip(start) |
| .take(count) |