Daniel Al-Makhamreh
Daniel Al-Makhamreh

Reputation: 87

Firebase realtime database saving data but not displaying it on console in flutter

I am working on an application that requires a real time database. Firebase has been working fine with the application. The real time database is accessible through http post and get and are causing the firebase database to update its data on the console.

The problem is when I attempt to change data using flutter functions provided by the library.

    final firebaseRef = FirebaseDatabase.instance.reference().child("Items");

    firebaseRef.set("hi");
    firebaseRef.once().then((DataSnapshot snapshot) {
      print('Data : ${snapshot.value}');
    });

When i attempt to use the functions above the data seems to be available and the console prints Data: hi, but they do not appear on the firebase console when i check it online.

Any help is appreciated, I cant find any information that can help. I checked my set up 20 times and its correct, open to any suggestions.

Upvotes: 0

Views: 1476

Answers (1)

Daniel Al-Makhamreh
Daniel Al-Makhamreh

Reputation: 87

I have figured out the problem with the help of Frank van Puffelen, thanks man. The problem was that the Firebase real-time database was not connected to the application and all the results i was getting were being cached on the device.

In case you run into a similar problem check whether the database is connected using the help of this part of the documentation. https://firebase.google.com/docs/database/android/offline-capabilities#section-connection-state

In my case the reason it was not connected was because when referencing any real-time Database on flutter that is outside central America you need to place the url of the databse found in the firebase console in your code. As such:

final firebaseRef = FirebaseDatabase(
        databaseURL:
            "https://yourfirebaseproject.europe-west1.firebasedatabase.app/")
    .reference()
    .child("Items");

I hope this is good enough to fix your problem.

Upvotes: 3

Related Questions