【发布时间】:2019-12-23 07:04:52
【问题描述】:
我正在尝试在颤振中使用 bloc 模式,但我遇到了一些问题,因为我需要实时获取数据,但是对于我拥有的 bloc,我只能在更新应用程序时获取数据,因为 bloc 使用 Http Get我需要使用 Stream ,有人可以帮助我吗?
这就是集团所做的:
final response = await client.get("$url/Proyectos/-Lm78GugBsy29c0Zxziy.json");
if (response.statusCode == 200) {
return ProyectoModel.fromJson(json.decode(response.body));
} else {
throw Exception('Failed to load post');
}
这就是我需要的:
StreamBuilder(
stream:dataBaseRef.child("Proyectos").child("Lm78GugBsy29c0Zxziy").onValue,
builder:(contex.snapshot){
if(snapshot.hasData){
return ProyectoModel.fromJson(snapshot.data.value);
}
},
);
【问题讨论】:
-
你在使用firestore吗?
标签: firebase-realtime-database flutter bloc