'TypeError when converting firebase data snapshot to map
I am currently following a Flutter tutorial and the instruction states that I retrieve data from Firestore and convert to a map, the tutorial uses the code below to achieve that.
Query query = db.collection(widget.dbName).orderBy("time");
// Map the documents to the data payload
slides = query.snapshots().map((list) => list.docs.map((doc) => doc.data));
After conversion, I'm supposed to pass the value into a StreamBuilder like so
StreamBuilder(
stream: slides,
initialData: [],
builder: (context, AsyncSnapshot snap) {
List slideList = snap.data.toList();
return PageView.builder(
controller: ctrl,
itemCount: slideList.length + 1,
itemBuilder: (context, int currentIdx) {
if (currentIdx == 0) {
return _buildTagPage();
} else if (slideList.length >= currentIdx) {
bool active = currentIdx == currentPage;
return _buildStoryPage(slideList[currentIdx - 1],
active, currentIdx - 1);
} else {
return Container();
}
});
}),
The _buildStoryPage function is given below
_buildStoryPage(Map data, bool active, int index) {
//.....
//....
}
The above code returns a type error message below
type '() => Map<String, dynamic>' is not a subtype of type 'Map<dynamic, dynamic>'
I've been struggling with this since yesterday and in my research I believe the error has to be from the way the data snapshot is converted to a map but I have not been able to find a way through this error.
Solution 1:[1]
Assign type to your _buildStoryPage function.
_buildStoryPage(Map<String, dynamic> data, bool active, int index) {
//.....
//....
}
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 | InFicial Infotech |
