Viibrant
Viibrant

Reputation: 23

Getting the error "type 'List<Map<String, Object>>' is not a subtype of type 'String' in type cast"

I get an error when I run the following code:

http.post(url,
body: {"access_token": "bfa67f6f8389f421d8ac0106f040d19b40d8a69112402a76b87d66aea86a",
  "title": "HelloWorld!",
  "content": [{
    "tag": "p",
      "children": 
        ["Hello world!"]
      }
    ],
  "return_content": true
},

I know that dart is complaining because I have an array which contains a map within my map. How can I deal with this?

EDIT: I would normally encode it as JSON but the API only accepts strings

Upvotes: 1

Views: 132

Answers (1)

lrn
lrn

Reputation: 71723

The body argument must have type String, and it doesn't. Your value looks like a JSON-like structure, so you probably want to encode that object structure as a String using the json encoder:

import "dart:convert";
...
var body = jsonEncode({"access_token": "..... " ... });
http.post(url, body: body);

Upvotes: 2

Related Questions