Commit 7939ec5d authored by Adam Barth's avatar Adam Barth

Merge pull request #336 from abarth/builder_index

ItemBuilder should also get the index of the item
parents 0758fea1 0259ad81
......@@ -18,7 +18,7 @@ class FitnessItemList extends StatelessComponent {
padding: const EdgeDims.all(4.0),
items: items,
itemExtent: kFitnessItemHeight,
itemBuilder: (BuildContext context, FitnessItem item) => item.toRow(onDismissed: onDismissed)
itemBuilder: (BuildContext context, FitnessItem item, int index) => item.toRow(onDismissed: onDismissed)
);
}
}
......
......@@ -16,7 +16,7 @@ class StockList extends StatelessComponent {
return new ScrollableList<Stock>(
items: stocks,
itemExtent: StockRow.kHeight,
itemBuilder: (BuildContext context, Stock stock) {
itemBuilder: (BuildContext context, Stock stock, int index) {
return new StockRow(
stock: stock,
onPressed: onOpen,
......
......@@ -400,7 +400,7 @@ class CardCollectionState extends State<CardCollection> {
snapOffsetCallback: _snapToCenter ? _toSnapOffset : null,
snapAlignmentOffset: _cardCollectionSize.height / 2.0,
items: _cardModels,
itemBuilder: (BuildContext context, CardModel card) => buildCard(context, card.value),
itemBuilder: (BuildContext context, CardModel card, int index) => buildCard(context, card.value),
itemExtent: _cardModels[0].height
);
} else {
......
......@@ -47,7 +47,7 @@ class PageableListAppState extends State<PageableListApp> {
});
}
Widget buildCard(BuildContext context, CardModel cardModel) {
Widget buildCard(BuildContext context, CardModel cardModel, int index) {
Widget card = new Card(
color: cardModel.color,
child: new Container(
......
......@@ -19,9 +19,9 @@ class ScrollbarAppState extends State<ScrollbarApp> {
return new ScrollableList<int>(
items: new List<int>.generate(_itemCount, (int i) => i),
itemExtent: _itemExtent,
itemBuilder: (_, int i) {
return new Text('Item ${dd.format(i)}',
key: new ValueKey<int>(i),
itemBuilder: (_, __, int index) {
return new Text('Item ${dd.format(index)}',
key: new ValueKey<int>(index),
style: Theme.of(context).text.title
);
},
......
......@@ -632,7 +632,7 @@ abstract class ScrollableWidgetListState<T extends ScrollableWidgetList> extends
}
typedef Widget ItemBuilder<T>(BuildContext context, T item);
typedef Widget ItemBuilder<T>(BuildContext context, T item, int index);
/// A wrapper around [ScrollableWidgetList] that helps you translate a list of
/// model objects into a scrollable list of widgets. Assumes all the widgets
......@@ -682,7 +682,7 @@ class ScrollableListState<T, Config extends ScrollableList<T>> extends Scrollabl
int begin = config.itemsWrap ? start : math.max(0, start);
int end = config.itemsWrap ? begin + count : math.min(begin + count, config.items.length);
for (int i = begin; i < end; ++i)
result.add(config.itemBuilder(context, config.items[i % itemCount]));
result.add(config.itemBuilder(context, config.items[i % itemCount], i));
return result;
}
}
......
......@@ -19,7 +19,7 @@ void handleOnDismissed(item) {
dismissedItems.add(item);
}
Widget buildDismissableItem(BuildContext context, int item) {
Widget buildDismissableItem(BuildContext context, int item, int index) {
return new Dismissable(
key: new ValueKey<int>(item),
direction: dismissDirection,
......
......@@ -8,7 +8,7 @@ const List<int> pages = const <int>[0, 1, 2, 3, 4, 5];
int currentPage = null;
bool itemsWrap = false;
Widget buildPage(BuildContext context, int page) {
Widget buildPage(BuildContext context, int page, int index) {
return new Container(
key: new ValueKey<int>(page),
width: pageSize.width,
......
......@@ -103,7 +103,7 @@ void main() {
tester.pumpWidget(new ScrollableList<int>(
items: <int>[0],
itemExtent: 100.0,
itemBuilder: (BuildContext context, int item) {
itemBuilder: (BuildContext context, int item, int index) {
return new Container(
key: new Key('container'),
height: 100.0,
......
......@@ -17,7 +17,7 @@ void main() {
child: new ScrollableList<int>(
key: new GlobalKey(),
items: items,
itemBuilder: (BuildContext context, int item) {
itemBuilder: (BuildContext context, int item, int index) {
return new Container(
key: new ValueKey<int>(item),
child: new GestureDetector(
......@@ -59,7 +59,7 @@ void main() {
child: new ScrollableList<int>(
key: new GlobalKey(),
items: items,
itemBuilder: (BuildContext context, int item) {
itemBuilder: (BuildContext context, int item, int index) {
return new Container(
key: new ValueKey<int>(item),
child: new GestureDetector(
......
......@@ -12,7 +12,7 @@ Widget buildFrame() {
height: 50.0,
child: new ScrollableList<int>(
items: items,
itemBuilder: (BuildContext context, int item) {
itemBuilder: (BuildContext context, int item, int index) {
return new Container(
key: new ValueKey<int>(item),
child: new Text('$item')
......
......@@ -8,7 +8,7 @@ const List<int> items = const <int>[0, 1, 2, 3, 4, 5];
Widget buildFrame() {
return new ScrollableList<int>(
items: items,
itemBuilder: (BuildContext context, int item) {
itemBuilder: (BuildContext context, int item, int index) {
return new Container(
key: new ValueKey<int>(item),
child: new Text('$item')
......
......@@ -13,7 +13,7 @@ const double itemExtent = 200.0;
ScrollDirection scrollDirection = ScrollDirection.vertical;
GlobalKey scrollableListKey;
Widget buildItem(BuildContext context, int item) {
Widget buildItem(BuildContext context, int item, int index) {
return new Container(
key: new ValueKey<int>(item),
width: itemExtent,
......
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