I try to assign a value to my Map<String, String> variable after I json-encode it and then json-decode it. The following code example is a simplified reproduce;
import 'dart:convert';
String toJson(dynamic object) {
var encoder = new JsonEncoder.withIndent(" ");
return encoder.convert(object);
}
dynamic fromJson(String jsonString) {
return json.decode(jsonString);
}
void main() {
Map<String, String> data = {"hello": "world"};
String jsonString = toJson(data);
data = fromJson(jsonString);
print(data);
}
When I run it, it fails with;
Unhandled exception:
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Map<String, String>'
And on this online editor it fails with a different error;
Uncaught exception:
TypeError: Instance of '_JsonMap': type '_JsonMap' is not a subtype of type 'Map<String, String>'