The Firebase Realtime Database and Flutter - Firecasts

Firebase · 88K views · 2021 · 59:26

Open on YouTube

Software (other)Web developmenttutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it as the official walkthrough for reading Realtime Database data into Flutter widgets, especially when they hit Map casting or StreamBuilder problems.

Recommended by 3 people across 3 different months, 2021 to 2022.

What it is

A one-hour Firecasts tutorial from the Firebase team on adding the Realtime Database to a Flutter app. It covers installing the library, writing and reading data, StreamBuilders, FutureBuilders, Providers, security rules and the emulator suite.

What people said

Recommends Tom3652 · 2021-07 · Stack Overflow · on “Get Map<String, dynamic> from Map<dynamic, dynamic> flutter”

This recent Firecast video [this video] solved my problem at 27min. I also had an non explicit Flutter error about another nested HashMap in my data model object that could not be converted directly. The solution is to use Map<String, dynamic>.from(snapshot.value) and this for every nested Map you have in your data model object EDIT : See Frank's answer below that is the correct one for the latest version of the firebase_database package.

Recommends Frank van Puffelen · 2022-04 · Stack Overflow · on “How can I retrieve data from firebase without refresh in flutter”

If you have data in the Firebase Realtime Database, you can listen to update to that data through its onValue stream [LINK] . You can use this stream in your widget tree by using a StreamBuilder : @override Widget build(BuildContext context) { var ref = FirebaseDatabase.instance.ref('path_to_value'); return Scaffold( StreamBuilder( stream: ref.onValue, builder: (context, snapshot) { if (snapshot.hasData) return Text(snapshot.data!.snapshot.value); if (!snapshot.hasData) return CircularProgressIndicator(); if (snapshot.hasError) return Text(snapshot.error); } ) ) I recommend watching this great code-along video: The Firebase Realtime Database and Flutter - Firecasts [this video]

Recommends Thaddeus · 2022-10 · Stack Overflow · on “How to go about loading all posts from firebase database in Flutter?”

If anybody else is trying to figure this out, I ended up following this tutorial [this video] , and it was very helpful! It uses a StreamBuilder to load data into a list, and it seems like a much more simple way to accomplish this than some of the other methods I looked into.

Cites Younghak Jang · 2021-11 · Stack Overflow · on “Flutter FutureBuilder not updating when setState() is called”

After reading comments here and FutureBuilder class documentation, I rewrote my code. Firebase Realtime Database youtube [this video] also helped me a lot. Variables were inside my build method because I had provider and needed context to load them(@il_boga). After all, I didn't need provider. I made a userProfileHandler class that does things my provider did, and just made a new instance of it. Documentation says combining FutureBuilder and calling SetState later is not a good choice. So I decided to use StreamBuilder instead of FutureBuilder. Since I'm not calling SetState, I changed entire widget to StatelessWidget. Now my photo updates when I pick new photo without reloading or visiting other

Cites Nana Kwame · 2022-01 · Stack Overflow · on “Can't cast _InternalLinkedHashMap<Object?, Object?> to anything”

I've been having some issues with get data from Firebase RealtimeDatabase as a Map despite me uploading it as a Map in the first place. All solutions I see are that you should just cast The snapshot.value to the data type incoming but no iteration of that works for me. I've been able to call toString() on the snapshot value and I've verified that it's a Map but the compiler doesn't even allow me to cast it to a Map let alone run it. If I try to use dynamic to prevent that compile error, I still get this Unhandled Exception: type '_InternalLinkedHashMap<Object?, Object?>' is not a subtype of type 'Map<String, dynamic>?' in type cast . This is what I've done, Future<Map<String, dynamic>> getBa

Cites edn · 2022-01 · Stack Overflow · on “Firebase RealTime database Flutter stream never returns problem”

I am trying to read a list of objects from Realtime database in Firebase with no success so far. I am following the official tutorial from Firecasts on the following link: [this video] Here is how the database looks like: [LINK] Here is the code I have written: The following is the class I have created for the objects I will be reading from database: class TestData { final String name; final String surname; final String age; TestData({ required this.name, required this.surname, required this.age, }); factory TestData.fromRTDB(Map<dynamic, dynamic> data) { return TestData( name: data["Name"], surname: data["Surname"], age: data["Age"], ); } } Here is how I try to read it from the database: class T

Cites Declan Morgan · 2022-01 · Stack Overflow · on “Cannot cast Snapshot Data as type Event”

I am connecting to my Realtime database in Flutter. I am using a StreamBuilder to build the results fetched from the onValue listener on the database. Following the video linked here [this video] , at timestamp 33:07, it says to cast the snapshot data as Event. When I do this in my app I get the error The name 'Event' isn't a type, so it can't be used in an 'as' expression. The only library it is hinting to import is the dart:html library, which is not what I want. I can't seem to find any other issues online associated with this. Here is my code: StreamBuilder( stream: _database.child('searchTrends/google/').onValue, builder: (context, snapshot){ final resList = <TrendCard>[]; if(snapshot.hasDat

Cites ssb31 · 2022-02 · Stack Overflow · on “How to pull snapshot key & values into list through Map<>?”

I've been following the official Firebase tutorial for using a real-time database: [this video] I am able to pull all the data from the firebase real-time database. However, the method below to do so, provides a list of the data, with no reference to the parent keys (snapshot.key). An ideal scenario would be to have a key property within the Item class (item.key), so I can call upon it directly from the list. class DatabaseModel { final itemsRef = FirebaseDatabase.instance.ref().child('/Contents'); Stream<List<Items>> getItemssStream() { final itemsStream = itemsRef.onValue; final streamToPublish = itemsStream.map((event) { final itemsMap = Map<String, dynamic>.from(event.snapshot.value as Map<St

Cites TB AS · 2022-05 · Stack Overflow · on “Why am I getting an 'type 'Null' is not a subtype of 'String'?”

I am struggling with getting the data from my 'Firebase'. The 'print(mUsers)' are getting me the users from 'Firebase', so it is working up to that point. So I think my problem is with this: 'final users = UserModel.fromRTDB(Map<String, dynamic>.from(value));' I see there is many ways to do this, but I have used this guide: [this video] Here is my StreamBuilder: StreamBuilder( stream: _database .child('brukere') .limitToLast(10) .onValue, builder: (context, snapshot){ final tilesList = <ListTile>[]; if(snapshot.hasData) { final mUsers = Map<String, dynamic>.from( (snapshot.data! as DatabaseEvent).snapshot.value as Map ); tilesList.addAll(mUsers.values.map((value) { print(mUsers); final users = Us