'Can't convert _InternalLinkedHashMap<String, dynamic> to Map<String, dynamic>
I'm trying to get data from cloud_firestore.
void _getData(){
final getData = await FirebaseFirestore.instance
.collection('users')
.doc(id)
.get();
Map<String, dynamic> d = getData.data()!;
for (dynamic i in d["tags"]) {
.......
}
}
But when _getData() is called, an error occurs at for (dynamic i in d["tags"]) .
_TypeError (type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Iterable<dynamic>')
I found this answer and changed my code.
Map<String, dynamic> d = getData.data()!;
to
Map<String, dynamic> d = Map<String, dynamic>.from(getData.data()!);
But the error never be fixed.
I don't want waste time with useless _InternalLinkedHashMap.
RunTimeType print
print("type: " + d["tags"].runtimeType.toString());
output
I/flutter (18762): type: _InternalLinkedHashMap<String, dynamic>
Solution 1:[1]
I found the error origin. when the specific document was broken, this error occurs.
In my case, I thought database was like this:
tags (array)
|- tag1 (map)
|- user (String)
|- date (Timestamp)
|- tag2 (map)
|- user (String)
|- date (Timestamp)
...
However the database was actually this:
tags (array)
|- user (String)
|- date (Timestamp)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | yuki yuki |
