This is the imported json for the firebase realTime DB:
"FAT6To4D48YRzhO3fz4VcEFIapZ2" : {
"groups" : {
"-MNKG-FRw9weSrPWQjOc" : true,
"-MNKG-FRw9weSrPWQjO1" : true
}
}
}
This is the code for fatching the information into flutter:
var user = _auth.currentUser.uid;
var fb = FirebaseDatabase.instance.reference();
List<Group> list = List();
var snapshot = await fb.child("userGroups").child(user).child("groups").once();
LinkedHashMap groups = snapshot.value;
groups.forEach((key, val) async {
var snaps = await fb.child('groups/$key').once();
LinkedHashMap val = snaps.value;
list.add(Group(
name: val['name'],
description: val['description'],
groupId: key,
));
});
return list;
}
Is this the correct way to do it? For now - the forEach loop is not iterating