stock_list.dart 910 字节
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
import 'package:sky/framework/components2/fixed_height_scrollable.dart';
import 'package:sky/framework/fn2.dart';
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
import 'stock_data.dart';
import 'stock_row.dart';

class Stocklist extends FixedHeightScrollable {
  String query;
  List<Stock> stocks;

  Stocklist({
    Object key,
    this.stocks,
    this.query
  }) : super(key: key);

  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);
  }
}