当我在浏览器中使用此代码输出时,断言失败:不正确。通常是这样的,因为数据没有发送到列表视图,对吧??但什么是错误的部分?
theftion trible tribrars捕获的例外╞═════════════════════════════════════════ ══════════════════ 在构建ItemActivity(脏)时抛出了以下断言:断言失败:不正确
这是我调用 API 时的代码
FutureBuilder(
future: UserController.getActivity(_selectedUser),
builder: (context, snapshot) {
if (snapshot.hasError) print(snapshot.error);
return snapshot.hasData
? new ItemActivity(
list: snapshot.data,
)
: new Center(
child: CircularProgressIndicator(),
);
}),
我在页面底部有这段代码,真的在小部件之外
class ItemActivity extends StatelessWidget {
final List list;
ItemActivity({this.list});
@override
Widget build(BuildContext context) {
return new ListView.builder(
itemCount: list == null ? 0 : list.length,
itemBuilder: (context, i) {
Map<String, dynamic> activity = list[i]['activity'];
return new Container(
padding: EdgeInsets.all(10.0),
child: Container(
child: Card(
child: new ListTile(
title: Text(activity.containsKey("project")
? activity["project"]
: "-"),
subtitle: Text("created at : ${list[i]['created_at']}"),
)),
),
);
},
);
}
}