Lalit Rawat
Lalit Rawat

Reputation: 1272

unable to read data from firestore

i trying to read data in firestore using json the type Map must implements iterable

Stream<List<RentModel>> readData(){
    var json = collection.document("rent").snapshots();
    List<RentModel> rentModel = List();
    return json.map((document) {
      for (var index in document.data){     // error is here in document.data that: the type Map<String, dynamic> must implements iterable 
        rentModel.add(RentModel.fromJson(index));
      }
      return rentModel;
    });
  }

Upvotes: 0

Views: 73

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80904

If you want to use for...in, then you need to have a class that implements an iterable such as List and Set, but document.data is of type Map.

If you want to iterate inside a map, then you can use forEach:

document.data.forEach((key,values) {
  print(key);
});

https://api.dart.dev/stable/2.3.1/dart-core/Map/forEach.html

Upvotes: 1

Related Questions