Home > Net >  how can get data from firebase use child value flutter?
how can get data from firebase use child value flutter?

Time:09-30

I want to retrieve data from firebase via "continent" value

here is my database enter image description here

this is my code

DatabaseReference ref=FirebaseDatabase.instance.reference().child("Country/").orderByChild("continent").equalTo("Asia");
ref.once().then((DataSnapshot datasnapshot){
datalist.clear();
var keys=datasnapshot.value.keys;
var values=datasnapshot.value;
for(var key in keys){

Country data=new Country(

    values[key]['Country'],
    values[key]['continent'],
    values[key]['Capital'],
 

                        );
datalist.add(data);

what is wrong?

CodePudding user response:

DatabaseReference ref=FirebaseDatabase.instance.reference().child("Country/").orderByChild("continent").equalTo("Asia");
ref.once().then((DataSnapshot snapshot){
  Map<dynamic, dynamic> values = snapshot.value;
     values.forEach((key,values) {
      print(values["continent"]);
    });
 });
  • Related