如何在Flutter Stream上使用Firebase RTDB [英] How To Use Firebase RTDB with Flutter Stream

查看:65
本文介绍了如何在Flutter Stream上使用Firebase RTDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在Flutter Stream Builder中使用Firebase RTDB(不是FireStore).我搜索了很多次,但找不到单个示例.所有示例都使用云存储.

Is there any way to use firebase RTDB(not FireStore) with Flutter Stream Builder. 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.

同时,这是从同一篇文章中获得的片段代码...

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";
}

这篇关于如何在Flutter Stream上使用Firebase RTDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆