fix: Broken nested accountData content maps

If you call BasicEvent.fromJson the given content is copied first
which recursively makes sure
that the Map is from type
Map<String,dynamic>.
Using just the constructor doesnt have this which can lead that nested Maps in
the content is InternallinkedHashMap and
therefore lead to type errors.
This commit is contained in:
Christian Pauly 2021-07-05 15:40:44 +02:00
parent af3a99af1c
commit 7c0dd5d8fd
1 changed files with 18 additions and 8 deletions

View File

@ -1053,15 +1053,25 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
}
}
Map<String, dynamic> convertToJson(Map map) {
final jsonMap = <String, dynamic>{
for (final entry in map.entries) ...{
if (entry.value is Map)
'${entry.key.toString()}': convertToJson(entry.value),
if (!(entry.value is Map)) '${entry.key.toString()}': entry.value,
dynamic _castValue(dynamic value) {
if (value is Map) {
return convertToJson(value);
}
};
return jsonMap;
if (value is List) {
return value.map(_castValue).toList();
}
return value;
}
/// Hive always gives back an `_InternalLinkedHasMap<dynamic, dynamic>`. This
/// creates a deep copy of the json and makes sure that the format is always
/// `Map<String, dynamic>`.
Map<String, dynamic> convertToJson(Map map) {
final copy = Map<String, dynamic>.from(map);
for (final entry in copy.entries) {
copy[entry.key] = _castValue(entry.value);
}
return copy;
}
class MultiKey {