0

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; }); } 
0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.