0
class _RecipesBodyState extends State<RecipesBody> {
  @override
  build(BuildContext context) {
    var docs = FirestoreService()
        .getCollectionData('recipes')  // <----------- Here
        .then((value) => print(value));

    return SafeArea(
      child: PageView(children: []),
    );
  }
}

I do print() to see the data but when I try to save the data in a variable like this

    var docs =
        FirestoreService().getCollectionData('recipes').then((value) => value);

    print(docs)

I get an Instance of Future<List<dynamic>> instead the data

the GetCollectionData() have this:

Future<List> getCollectionData(String collection) async {
    var data = [];
    QuerySnapshot<Object?> querySnapshot =
        await _db.collection(collection).get();
    List<QueryDocumentSnapshot<Object?>> docs = querySnapshot.docs;

    for (var doc in docs) {
      data.add(doc.data());
    }

    return data;
  }

I tried to make a list variable and declare its value in the then but it didn't work either.

JoseDv1
  • 11
  • 2
  • It's a future which means it could contain data of different types in it. You need to go further/deeper into the specific data you want to print/show – Davis Feb 07 '23 at 17:48

0 Answers0