Home > other >  flutterfire realtime database a children to dynamic list
flutterfire realtime database a children to dynamic list

Time:06-08

I am new on flutter. Now i am trying to get a children from realtime database to dynamic list. and with that list i need count them and create box. but when i try that i get all datasnapshot in one box with datakey.

My future class:

Future<dynamic> getdata() async { 
  final ref = FirebaseDatabase.instance.ref("Categories");
  final snapshot = await ref.get();
  if (snapshot.exists) {
       entry.add(snapshot.value);
   print(entry);
  } else {
      print('No data available.');
  } 
}
late List<dynamic> entry =[];

my output

I/flutter (13624): [{-N3lX7tMzVVT7gqUF_1q: deneme, -N3lX9bwkr3X6J3wfHfq: deneme1, -N3lXAwEnNKQ1WcA4Vw2: deneme2, -N3lXFEq5RV5HXkfHiVF: deneme3}]

so i want this one by one not in one line and just data not key. with that i will create box and write there .

CodePudding user response:

It sounds like you want to loop over the children of the snapshot you get from Firebase, which you can do with:

final ref = FirebaseDatabase.instance.ref("Categories");
final snapshot = await ref.get();
if (snapshot.exists) {
  snapshot.children.forEach((child) { //            
  • Related