flutter list generate code example

Example 1: generate list flutter

List<int>.generate(3, (int index) => index * index); // [0, 1, 4]

Example 2: list widget flutter

ListView(
  padding: const EdgeInsets.all(8),
  children: <Widget>[
    Container(
      height: 50,
      color: Colors.amber[600],
      child: const Center(child: Text('Entry A')),
    ),
    Container(
      height: 50,
      color: Colors.amber[500],
      child: const Center(child: Text('Entry B')),
    ),
    Container(
      height: 50,
      color: Colors.amber[100],
      child: const Center(child: Text('Entry C')),
    ),
  ],
)

Example 3: flutter list.generate

final items = List<String>.generate(10000, (i) => "Item $i");

Example 4: dart list generate

new List<int>.generate(3, (int index) => index * index); // [0, 1, 4]

Tags:

Misc Example