我收到错误event.snapshot.value
自从更新到 firebase 9.0.5 以来。
我有很多这样的函数,它们在 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;
}
现在我有错误标记event.snapshot.value
,and android studio 说
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)));
当我尝试时
Map<String, dynamic>.from(event.snapshot.value as Map<String, dynamic>).forEach((key, value) =>
然后错误标记消失了,但是当我运行应用程序时它会返回
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:
Firebase 9.0 到底发生了什么变化?如何在 firebase 9.0 中迭代 event.snapshot.value ?