RiseHit
RiseHit

Reputation: 319

how can i get the value of a child in firebase database realtime in flutter?

I would like to be able to obtain the data that is inside grupofav, this data is equivalent to grupoid3, but I cannot access the reference that is equivalent to that value in firebase database real-time, the idea is to be able to pass the id of the favourite group to another reference accessing that particular group.

I tried doing this

var grupoFav = FirebaseDatabase.instance
  .ref()
  .child("usuarios")
  .child("T1gMWDq6d6R6cKSyd8StjKV8drg1")
  .child("grupofav")
  .get()
  .toString();

but with get, onvalue and others, I couldn't get to the data

image refence

Upvotes: 0

Views: 2506

Answers (2)

Frank van Puffelen
Frank van Puffelen

Reputation: 600131

get is an asynchronous operation, so you'll need to await its result:

var dbRef = FirebaseDatabase.instance
  .ref()
  .child("usuarios")
  .child("T1gMWDq6d6R6cKSyd8StjKV8drg1")
  .child("grupofav")
var snapshot = await dbRef.get(); // 👈 Use await here
var grupoFav = snapshot.value;    // 👈 Use value here

Upvotes: 1

Dipak Prajapati
Dipak Prajapati

Reputation: 390

try following

FirebaseDatabase.instance
  .ref()
  .child("usuarios")
  .orderByChild('groupfav')
  .get();
  

Upvotes: 0

Related Questions