Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(973)

Unified Diff: sky/sdk/example/stocks/lib/stock_list.dart

Issue 1219933004: Make it harder to forget itemCount for FixedHeightScrollable (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/sdk/example/demo_launcher/lib/main.dart ('k') | sky/sdk/lib/widgets/fixed_height_scrollable.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « sky/sdk/example/demo_launcher/lib/main.dart ('k') | sky/sdk/lib/widgets/fixed_height_scrollable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698