iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🎃

[Flutter] Using for-loops within the children property

に公開

In React, array data is often converted into components using .map, but in Flutter, it's common to use asMap since you can't easily get the index.

I learned about a pattern for using a for loop within the children list, so here is a note on it.

class ItemList extends StatelessWidget {
  const ItemList({
    required this.itemList,
  });

  final ItemList itemList;

  @override
  Widget build(BuildContext context) {
    return Wrap(
      runSpacing: 8,
      children: [
        for (final item in itemList)
          Item(
            item: item,
          ),
      ],
    );
  }
}

Discussion