简体   繁体   English

如何在Flutter Stream中使用Firebase RTDB

[英]How To Use Firebase RTDB with Flutter Stream

Is there any way to use firebase RTDB(not FireStore) with Flutter Stream Builder. 有什么方法可以在Flutter Stream Builder中使用Firebase RTDB(不是FireStore)。 I search many times but I cannot find a single example. 我搜索了很多次,但找不到单个示例。 all the example are using cloud fire store. 所有示例都使用云存储。

You can refer to this medium article, they have explained how to use StreamBuilders with Firebase RTDB. 你可以参考这个媒体的文章,他们解释如何使用StreamBuilders与火力地堡实时数据库。

In the meantime, here's a piece code derived from the same article... 同时,这是从同一篇文章获得的片段代码...

//first make a reference to your firebase database

var recentJobsRef = FirebaseDatabase.instance
.reference()
.child('recent')
.orderByChild('created_at') 
.limitToFirst(10);

//then use StreamBuilders like this

StreamBuilder(
stream: recentJobsRef.onValue,
builder: (BuildContext context, snapshot) {
if(snapshot.hasData) => return "Has Data";
else if(snapshot.hasError) => return "Error";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM