gpt4 book ai didi

google-cloud-firestore - 使用 Flutter 和 Firestore 显示某些数据

转载 作者:IT王子 更新时间:2023-10-29 07:01:01 26 4
gpt4 key购买 nike

我目前正在使用这段代码来映射整个待办事项列表:

return new StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection('todo_list').snapshots,
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) return new Text('Loading...');
return new ListView(
children: snapshot.data.documents.map((DocumentSnapshot document) {
document['status'] == true ?
new ListTile(
title: new Row(
children: <Widget>[
new Expanded(
child: new Text(document['task'],
style: new TextStyle(
decoration: TextDecoration.lineThrough,
),
),
)
],
)
) : new Text("");
}).toList(),
);
},
);

我想显示状态为 true 的任务。但是,这样做时出现错误:

I/flutter (21800): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (21800): The following assertion was thrown during performLayout():
I/flutter (21800): 'package:flutter/src/widgets/sliver.dart': Failed assertion: line 291 pos 12: 'child != null': is
I/flutter (21800): not true.
I/flutter (21800):
I/flutter (21800): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (21800): more information in this error message to help you determine and fix the underlying cause.
I/flutter (21800): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (21800): https://github.com/flutter/flutter/issues/new
I/flutter (21800):
I/flutter (21800): When the exception was thrown, this was the stack:
I/flutter (21800): #2 SliverChildListDelegate.build (package:flutter/src/widgets/sliver.dart)
I/flutter (21800): #3 SliverMultiBoxAdaptorElement._build.<anonymous closure> (package:flutter/src/widgets/sliver.dart:716:67)
I/flutter (21800): #4 _HashMap.putIfAbsent

...

有什么建议吗?

最佳答案

您忘记返回三元的实际结果。

return  document['status'] == true ?
....

这应该可以解决问题

关于google-cloud-firestore - 使用 Flutter 和 Firestore 显示某些数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50304331/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com