I am following this tutorial so that i can read the data of an event https://petercoding.com/firebase/2020/02/16/using-firebase-queries-in-flutter/ I went to the Reading data section "Retrieving The Firebase Data in a ListView"
I pasted the code in my code and i cannot find in the tutorial where should i create the "lists" list. Can anyone tell me what list should i define so it works?
FutureBuilder(
future: databaseReference.once(),
builder: (context, AsyncSnapshot<DataSnapshot> snapshot) {
if (snapshot.hasData) {
lists.clear();
Map<dynamic, dynamic> values = snapshot.data.value;
values.forEach((key, values) {
lists.add(values);
});
return new ListView.builder(
shrinkWrap: true,
itemCount: lists.length,
itemBuilder: (BuildContext context, int index) {
return Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Name: " + lists[index]["name"]),
Text("Age: "+ lists[index]["age"]),
Text("Type: " +lists[index]["type"]),
],
),
);
});
}
return CircularProgressIndicator();
}),