Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Use Firebase RTDB with Flutter Stream

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.

like image 233
NicoleZ Avatar asked Mar 09 '19 05:03

NicoleZ


People also ask

How to use Firebase Realtime Database in flutter?

After you have integrated Firebase to your Flutter application and adding firebase_database as a dependency, you should be able to use Firebase Realtime Database by adding the import below. In order to perform data operations, you need to get the DatabaseReference object, which refers to a particular location (node) in the database.

What is Firebase and how to use it?

Firebase helps developers to build and run their apps successfully, its backend developed by Google. Firebase is very easy to use for beginners, it provides many functionalities like Firebase Authentication, Cloud Firestore, Realtime Database, Firebase Storage, etc which help to build and optimize the application.

Should I use realtime database or Google Firebase?

Realtime Database is the clear choice as it’s cheaper, easier to use and faster to run. Check out the full list of comparisons on Google’s product page. Switch to our Cloud Firestore tutorial if you’re looking to explore the Firestore solution. Before you can use any of Google’s cloud services, you have to set up a project on the Firebase Console.

What is flutter SDK and how to use it?

Google’s Flutter SDK can be used to develop apps that give native UI experience for both Android and iOS platforms. To write apps using Flutter, you have to use Dart programming language. Firebase Realtime Database is a cloud-hosted database with data stored as JSON.


1 Answers

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";
}
like image 168
Ashutosh Singh Avatar answered Sep 25 '22 04:09

Ashutosh Singh