如何在 ListView 中使用列表,在 Flutter 中使用 ListTile
How can I use a list in ListView and ListTile in Flutter
我正在尝试通过迭代列表来创建 ListView,但出现此错误:
package:flutter/src/material/list_tile.dart': Failed assertion: line 1002 pos 12: 'color != null || context != null': is not true.
我该如何解决这个问题?这是我的代码:
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()));
ListTile.divideTiles
需要颜色参数:
在ListTile.divideTiles
中指定颜色即可。
正如上面的答案所指出的,你不能将两个参数都保留为 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())
这必须有效
我正在尝试通过迭代列表来创建 ListView,但出现此错误:
package:flutter/src/material/list_tile.dart': Failed assertion: line 1002 pos 12: 'color != null || context != null': is not true.
我该如何解决这个问题?这是我的代码:
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()));
ListTile.divideTiles
需要颜色参数:
在ListTile.divideTiles
中指定颜色即可。
正如上面的答案所指出的,你不能将两个参数都保留为 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())
这必须有效