Commit b5b7ddac authored by Adam Barth's avatar Adam Barth

Make Stocks app search actually search

We don't yet reset the scroll offset, so sometimes you can't see your search
results properly.

R=rafaelw@chromium.org

Review URL: https://codereview.chromium.org/1002453003
parent bc6fb30f
part of stocksapp;
class Stocklist extends FixedHeightScrollable {
String query;
List<Stock> stocks;
Stocklist({
Object key,
this.stocks
this.stocks,
this.query
}) : super(key: key, minOffset: 0.0);
List<Node> buildItems(int start, int count) {
var items = [];
for (var i = 0; i < count; i++) {
items.add(new StockRow(stock: stocks[start + i]));
}
return items;
return stocks
.skip(start)
.where((stock) => query == null || stock.symbol.contains(
new RegExp(query, caseSensitive: false)))
.take(count)
.map((stock) => new StockRow(stock: stock))
.toList(growable: false);
}
}
......@@ -42,6 +42,7 @@ class StocksApp extends App {
List<Stock> _sortedStocks;
bool _isSearching = false;
String _searchQuery;
StocksApp() : super() {
_sortedStocks = oracle.stocks;
......@@ -54,6 +55,12 @@ class StocksApp extends App {
});
}
void _handleSearchQueryChanged(query) {
setState(() {
_searchQuery = query;
});
}
Node build() {
var drawer = new Drawer(
animation: _drawerAnimation,
......@@ -86,9 +93,13 @@ class StocksApp extends App {
]
);
Node title = _isSearching
? new Input(focused: true, placeholder: 'Search stocks')
: new Text('I am a stocks app');
Node title;
if (_isSearching) {
title = new Input(focused: true, placeholder: 'Search stocks',
onChanged: _handleSearchQueryChanged);
} else {
title = new Text('I am a stocks app');
}
var toolbar = new Toolbar(
children: [
......@@ -110,6 +121,8 @@ class StocksApp extends App {
]
);
var list = new Stocklist(stocks: _sortedStocks, query: _searchQuery);
var fab = new FloatingActionButton(content: new Icon(
type: 'content/add_white', size: 24));
......@@ -119,7 +132,7 @@ class StocksApp extends App {
new Container(
key: 'Content',
style: _style,
children: [toolbar, new Stocklist(stocks: _sortedStocks)]
children: [toolbar, list]
),
fab,
drawer,
......
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