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