currently i'm using firestore and realtime database at the same time. I set and retrieve from firestore in the most simplest and effective way in code and for realtime database i set data but i couldn't retrieve it in the same way that i do with firestore. Summary i want to do the same thing which i do with firestore code in realtime database code.
Here is my code:
//Get data from Firestore
Stream <DocumentSnapshot> getData() async*{
final user = FirebaseAuth.instance.currentUser;
yield* FirebaseFirestore.instance.collection('users').doc(user.uid).snapshots();
}
//Return data in StreamBuilder (No lists or ListView.Builder needed here)
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: getData(),
builder: (context, snapshot) {
//--------------------------------------
//These equations comes from Firestore
//--------------------------------------
int currentWater ()=> snapshot.data['currentLitersAmount'];
int remainingWater () => snapshot.data['currentLitersAmount'] <= snapshot.data['recomendedLitersAmount'] ? snapshot.data['recomendedLitersAmount'] - snapshot.data['currentLitersAmount'] : 0;
double progress ()=> snapshot.data['currentLitersAmount'] / snapshot.data['recomendedLitersAmount'];
So how to do the same thing here for realtime database?