自从更新到firebase 9.0.5之后,我在event.snapshot.value上得到了错误。我有许多像这样的函数,在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上有了错误标记,android说
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: 火柴9.0到底发生了什么变化?如何在FireBase9.0中迭代event.snapshot.value?
发布于 2022-01-17 13:02:28
从Firebase v9,他们从使用dynamic转移到Object?,开始将Object?转换为Map可能会很麻烦,因为experienced..Simply使对象dynamic可以消除麻烦。
尝试:
Map<String, dynamic>.from(event.snapshot.value as dynamic).forEach((key, value) => _mentorList.add(MentorModel.fromRTDB(key, value)));发布于 2022-02-15 00:27:20
‘statut: json'statut’!= null?(json‘’statut‘作为列表).map((I) => Statut.fromJson(Map.from(作为动态的)).toList():null,
https://stackoverflow.com/questions/70741649
复制相似问题