Here is my code:
Map<String, dynamic>? myMap = {
‘conversationId’: iD,
‘type’: ‘text’,
‘data’: _controller.text.toString(),
‘msgLength’:_controller.text.length,
‘senderId’: Provider.of( context,listen: false).id,
‘createdOn’: 190823,
‘messageState’: ‘delivered’,
‘isDeleted’: 0,
‘id’: 3048,
};
String encoded = json.encode(myMap);
// Make the POST request and wait for the response
final response = await postRequest(url: conversationUrl,
body: encoded,
headers:{'Content-Type': 'application/json'},);
BUT I AM SHOWN a RED LINE UNDER encoded in the body parameter, with the error: The argument type ‘String’ can’t be assigned to the parameter type ‘Map<String, dynamic>?’
I have tried (Dart HTTP POST with Map<String, dynamic> as body) changes, now what?
2
Answers
So what I think might be happening is an issue in the way the json is being encoded, maybe
We usually do
Also, the docs for json encode say this:
Try making the String encoded of type final
The body takes the map, not the encoded string. Simply use