convertPlatformMap function
Converts a platform channel map to a typed Dart map.
input The raw map from the platform channel.
Returns a typed map with string keys and dynamic values.
Throws ArgumentError if the input is not a map.
Implementation
Map<String, dynamic> convertPlatformMap(dynamic input) {
if (input is! Map) {
throw ArgumentError('Expected a Map but got ${input.runtimeType}');
}
final result = <String, dynamic>{};
for (final entry in input.entries) {
final key = entry.key;
if (key is! String) {
PluginLogger.warning('Non-string key found in platform map: $key');
continue;
}
final value = entry.value;
if (value is Map) {
result[key] = convertPlatformMap(value);
} else if (value is List) {
result[key] = _convertList(value);
} else {
result[key] = value;
}
}
return result;
}