'Dart json.decode can't decode to Map<String, String>

My code:

import 'dart:convert';

String jsonString = '''{
"a": "g",
"b": "h",
"c": "j",
"d": "k"
}''';

Map<String, String> map = json.decode(jsonString);

Getting the error:

Unhandled exception:
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Map<String, String>'
#0      main (file:///...)
#1      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:298:32)
#2      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:171:12)

Map<String, dynamic> map ... and Map<String, Object> map ... Are working.

I am trying to de serialize in the end Map<String, Map> for different JSON and it gave me the same error so I have decided to first work with the basic which is the Map<String, String> to better understand what am I doing wrong



Solution 1:[1]

when I worked with firebase messaging. I enforced to do like this receive body of the notification. I don't know the reason but I solve it like this:

Map<String, String> valueMap = Map.castFrom(json.decode(json.decode(payload!)));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Feisal Aswad