stock_list.dart 1.1 KB
Newer Older
1 2 3 4
// 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.

5 6 7
import 'package:sky/framework/widgets/fixed_height_scrollable.dart';
import 'package:sky/framework/widgets/wrappers.dart';

8 9 10 11 12 13 14 15 16
import 'stock_data.dart';
import 'stock_row.dart';

class Stocklist extends FixedHeightScrollable {

  Stocklist({
    Object key,
    this.stocks,
    this.query
17
  }) : super(itemHeight: StockRow.kHeight, key: key);
18

19 20 21 22 23 24 25 26 27
  String query;
  List<Stock> stocks;

  void syncFields(Stocklist source) {
    query = source.query;
    stocks = source.stocks;
    super.syncFields(source);
  }

28 29 30 31 32 33 34 35 36 37 38 39 40
  List<UINode> 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)
      .map((stock) => new StockRow(stock: stock))
      .toList(growable: false);
  }
}