Switch clients of ScrollableList to ScrollableList2
This patch also changed ScrollableList2 to use an Iterable instead of an List for its children. This change lets clients map their underlying data lazily. If the clients actually have a concrete list, we skip the extra copy and grab the child list directly.
This commit is contained in:
@@ -14,11 +14,10 @@ class FitnessItemList extends StatelessComponent {
|
||||
final FitnessItemHandler onDismissed;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new ScrollableList<FitnessItem>(
|
||||
return new ScrollableList2(
|
||||
padding: const EdgeDims.all(4.0),
|
||||
items: items,
|
||||
itemExtent: kFitnessItemHeight,
|
||||
itemBuilder: (BuildContext context, FitnessItem item, int index) => item.toRow(onDismissed: onDismissed)
|
||||
children: items.map((FitnessItem item) => item.toRow(onDismissed: onDismissed))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,9 @@ class StockList extends StatelessComponent {
|
||||
final StockRowActionCallback onAction;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new ScrollableList<Stock>(
|
||||
items: stocks,
|
||||
return new ScrollableList2(
|
||||
itemExtent: StockRow.kHeight,
|
||||
itemBuilder: (BuildContext context, Stock stock, int index) {
|
||||
children: stocks.map((Stock stock) {
|
||||
return new StockRow(
|
||||
keySalt: keySalt,
|
||||
stock: stock,
|
||||
@@ -25,7 +24,7 @@ class StockList extends StatelessComponent {
|
||||
onDoubleTap: onShow,
|
||||
onLongPressed: onAction
|
||||
);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,12 +393,11 @@ class CardCollectionState extends State<CardCollection> {
|
||||
Widget build(BuildContext context) {
|
||||
Widget cardCollection;
|
||||
if (_fixedSizeCards) {
|
||||
cardCollection = new ScrollableList<CardModel> (
|
||||
cardCollection = new ScrollableList2 (
|
||||
snapOffsetCallback: _snapToCenter ? _toSnapOffset : null,
|
||||
snapAlignmentOffset: _cardCollectionSize.height / 2.0,
|
||||
items: _cardModels,
|
||||
itemBuilder: (BuildContext context, CardModel card, int index) => _buildCard(context, card.value),
|
||||
itemExtent: _cardModels[0].height
|
||||
itemExtent: _cardModels[0].height,
|
||||
children: _cardModels.map((CardModel card) => _buildCard(context, card.value))
|
||||
);
|
||||
} else {
|
||||
cardCollection = new ScrollableMixedWidgetList(
|
||||
|
||||
@@ -74,12 +74,12 @@ class MediaQueryExample extends StatelessComponent {
|
||||
if (MediaQuery.of(context).size.width < _gridViewBreakpoint) {
|
||||
return new ScrollableList2(
|
||||
itemExtent: 50.0,
|
||||
children: items.map((AdaptiveItem item) => item.toListItem()).toList()
|
||||
children: items.map((AdaptiveItem item) => item.toListItem())
|
||||
);
|
||||
} else {
|
||||
return new ScrollableGrid(
|
||||
delegate: new MaxTileWidthGridDelegate(maxTileWidth: _maxTileWidth),
|
||||
children: items.map((AdaptiveItem item) => item.toCard()).toList()
|
||||
children: items.map((AdaptiveItem item) => item.toCard())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,21 @@
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
final NumberFormat _dd = new NumberFormat("00", "en_US");
|
||||
|
||||
class _Item extends StatelessComponent {
|
||||
_Item(this.index);
|
||||
|
||||
int index;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new Text('Item ${_dd.format(index)}',
|
||||
key: new ValueKey<int>(index),
|
||||
style: Theme.of(context).text.title
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ScrollbarApp extends StatefulComponent {
|
||||
ScrollbarAppState createState() => new ScrollbarAppState();
|
||||
}
|
||||
@@ -15,17 +30,10 @@ class ScrollbarAppState extends State<ScrollbarApp> {
|
||||
final ScrollbarPainter _scrollbarPainter = new ScrollbarPainter();
|
||||
|
||||
Widget _buildMenu(BuildContext context) {
|
||||
NumberFormat dd = new NumberFormat("00", "en_US");
|
||||
return new ScrollableList<int>(
|
||||
items: new List<int>.generate(_itemCount, (int i) => i),
|
||||
return new ScrollableList2(
|
||||
itemExtent: _itemExtent,
|
||||
itemBuilder: (_, __, int index) {
|
||||
return new Text('Item ${dd.format(index)}',
|
||||
key: new ValueKey<int>(index),
|
||||
style: Theme.of(context).text.title
|
||||
);
|
||||
},
|
||||
scrollableListPainter: _scrollbarPainter
|
||||
scrollableListPainter: _scrollbarPainter,
|
||||
children: new List<Widget>.generate(_itemCount, (int i) => new _Item(i))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user