I'm getting errors on event.snapshot.value since updating to firebase 9.0.5.
I have many functions like this which worked fine in firebase 8.X.
Stream<List<MentorModel>> mentorStream() {
final stream = _database.onValue;
final Stream<List<MentorModel>> resultStream = stream.map((event) {
List<MentorModel> _mentorList = [];
Map<String, dynamic>.from(event.snapshot.value).forEach((key, value) => _mentorList.add(MentorModel.fromRTDB(key, value)));
return _mentorList;
});
return resultStream;
}
Now I have error marks on event.snapshot.value, and android studio says
Error: The argument type 'Object?' can't be assigned to the parameter type 'Map<dynamic, dynamic>'.
- 'Object' is from 'dart:core'.
- 'Map' is from 'dart:core'.
Map<String, dynamic>.from(event.snapshot.value).forEach((key, value) => _mentorList.add(MentorModel.fromRTDB(key, value)));
When I try
Map<String, dynamic>.from(event.snapshot.value as Map<String, dynamic>).forEach((key, value) =>
then the error marker is gone but when I run the app it returns
E/flutter (16737): [ERROR:flutter/shell/common/shell.cc(93)] Dart Unhandled Exception: type '_InternalLinkedHashMap<Object?, Object?>' is not a subtype of type 'Map<String, dynamic>' in type cast, stack trace:
What exactly changed in firebase 9.0? How can I iterate through event.snapshot.value in firebase 9.0?