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:
parent
af3a99af1c
commit
7c0dd5d8fd
|
|
@ -1053,15 +1053,25 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
|||
}
|
||||
}
|
||||
|
||||
dynamic _castValue(dynamic value) {
|
||||
if (value is Map) {
|
||||
return convertToJson(value);
|
||||
}
|
||||
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 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,
|
||||
}
|
||||
};
|
||||
return jsonMap;
|
||||
final copy = Map<String, dynamic>.from(map);
|
||||
for (final entry in copy.entries) {
|
||||
copy[entry.key] = _castValue(entry.value);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
class MultiKey {
|
||||
|
|
|
|||
Loading…
Reference in New Issue