flutter - 自更新到 firebase 9 以来出现错误 event.snapshot.value。0.X
flutter - errors event.snapshot.value since updating to firebase 9.0.X
自从更新到 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) =>
然后错误标记消失了,但是当我 运行 应用程序时 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:
Firebase 9.0 到底有什么变化?如何在 firebase 9.0 中遍历 event.snapshot.value?
从 Firebase v9 开始,他们从使用 dynamic
转移到 Object?
并且开始将 Object?
转换为 Map
可能会很麻烦,正如您所经历的那样。 .只需制作对象 dynamic
即可消除麻烦。
尝试:
Map<String, dynamic>.from(event.snapshot.value as dynamic).forEach((key, value) => _mentorList.add(MentorModel.fromRTDB(key, value)));
状态:json['statut'] != null ? (json['statut'] as List).map((i) => Statut.fromJson(Map.from(i as dynamic))).toList() :空,
自从更新到 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) =>
然后错误标记消失了,但是当我 运行 应用程序时 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:
Firebase 9.0 到底有什么变化?如何在 firebase 9.0 中遍历 event.snapshot.value?
从 Firebase v9 开始,他们从使用 dynamic
转移到 Object?
并且开始将 Object?
转换为 Map
可能会很麻烦,正如您所经历的那样。 .只需制作对象 dynamic
即可消除麻烦。
尝试:
Map<String, dynamic>.from(event.snapshot.value as dynamic).forEach((key, value) => _mentorList.add(MentorModel.fromRTDB(key, value)));
状态:json['statut'] != null ? (json['statut'] as List).map((i) => Statut.fromJson(Map