【发布时间】:2021-11-30 18:57:56
【问题描述】:
我还有一个检查数据的流。
class StufenService {
String userID;
StufenService(this.userID);
final CollectionReference userTodos =
FirebaseFirestore.instance.collection('userTodos');
Stream<QuerySnapshot> getStufe() {
var stufe = userTodos.where('Stufe', isEqualTo: 1);
stufe = stufe.where('userID', isEqualTo: userID);
return stufe.snapshots();
}}
我在 StreamBuilder 中使用流:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
backgroundColor: Color.fromRGBO(35, 112, 192, 1),
),
body: FutureBuilder(
future: standard(),
builder: (BuildContext context, AsyncSnapshot<void> snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return Center(child: CircularProgressIndicator());
} else {
return StreamBuilder<QuerySnapshot>(
stream: stufenService.getStufe(),
builder:
(context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
}
if (snapshot == ({'Stufe', 1})) {
return ToDo1F();} else
return ListView.separated(
separatorBuilder: (BuildContext context, int index) {
return SizedBox(
height: 10,
);
},
padding: EdgeInsets.all(10),
itemCount: Stufen.length,
itemBuilder: (BuildContext, i) {
String key = Stufen.keys.elementAt(i);
return StufenItem(
key,
Stufen[key]!,
() => toggleDone(key),
() => select(key),
);
});
},
);
}
}));
}
}
很遗憾,我无法返回流的数据。 我在这里试试:
if (snapshot.data == ({'Stufe', 1})) {
return ToDo1F();}
我不认为这是要走的路。有谁知道这是怎么做到的吗?还有什么问题吗? 感谢您的宝贵时间!
【问题讨论】:
-
你遇到了什么错误?
-
嗨..所以你想在 ListView 中显示 userTodos 的文档数据?
-
@AsimJawad 没有错误。当我在 ListView 中选择一个 Stufe (= Level) 时,我希望 Stream 能够识别这一点并将我分配给用户选择的 Level 的页面返回
-
@Garth 我希望 Stream 观看 'Stufe:int' (= Level:int) 并返回不同的页面,因为级别数发生了变化。
if (snapshot.data == ({'Stufe', 1})) { return ToDo1F();}例如,如果level:1存储在用户的文档中,则流应该返回ToDoF1()。
标签: firebase flutter google-cloud-firestore google-cloud-storage flutter-test