Solved: How can I use a list in ListView and ListTile in Flutter

Question

Asked by M-N on December 04, 2021 (source).

I'm trying to create a ListView by iterating list but I get this error:

package:flutter/src/material/list_tile.dart': Failed assertion: line 1002 pos 12: 'color != null || context != null': is not true.

How can I resolve this? Heres my code:

ListView(
        children: ListTile.divideTiles(
            tiles: _people.map((item) => ListTile(
                  leading: CircleAvatar(
                    backgroundColor: Colors.amber,
                    child: Text(item['id'].toString()),
                  ),
                  title: Text(item['name']),
                  subtitle: Text(item['descrip']),
                  trailing: IconButton(
                    icon: Icon(Icons.delete),
                    onPressed: () {},
                  ),
                ))).toList()));

Answer

Question answered by Rexford A (source).

As pointed by the above answer you can't leave both params as null

ListView(
      children: ListTile.divideTiles(
        color: Colors.red,
        context: context,
    tiles: _people.map(
      (item) => ListTile(
        leading: CircleAvatar(
          backgroundColor: Colors.amber,
          child: Text(item['id'].toString()),
        ),
        title: Text(item['name']),
        subtitle: Text(item['descrip']),
        trailing: IconButton(
          icon: Icon(Icons.delete),
          onPressed: () {},
        ),
      ),
    ),
  ).toList())

This has to work

DART FLUTTER LISTTILE LISTVIEW
SHARE: