[英]How can I use a list in ListView and ListTile in Flutter
I'm trying to create a ListView by iterating list but I get this error:我正在尝试通过迭代列表来创建 ListView,但出现此错误:
package:flutter/src/material/list_tile.dart': Failed assertion: line 1002 pos 12: 'color:= null ||
package:flutter/src/material/list_tile.dart':断言失败:第 1002 行第 12 行:'color:= null || context.= null': is not true.
context.= null': 不正确。
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()));
As pointed by the above answer you can't leave both params as null正如上述答案所指出的,您不能将两个参数都保留为 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这必须工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.