Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
520 views
in Technique[技术] by (71.8m points)

dart - Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<Map<dynamic, dynamic>>' Flutter Firebase

I am trying to get a list from firebase document and then set to another empty List of maps then add a map to this list of maps and pass it back to Firebase.

This is My method:

Future logFinalWorkout(user, finalWorkout) async{
 List<Map<dynamic, dynamic>> result = List<Map<dynamic, dynamic>>();
await users.document(user.uid).get().then((doc){
  result = doc.data['finalWorkouts'];
  result.addAll(finalWorkout);
});
return await users.document(user.uid).updateData({
  'finalWorkouts' : result,
});

}

finalWorkout parameter is of type Map<dynamic,dynamic> final workouts represents the list coming from Firebase. I keep getting the above error


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Remove List<Map<dynamic, dynamic>> result and add List< dynamic> result instead of that. Give it a try.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...