Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Future setInterests(String token, List<String> interests) {
return _netUtil.post(BASE_URL + "/setinterests", body: {
"token": token,
"interests": interests
}).then((dynamic res) {
return res;
Passing _filters always throws the error:
type 'List<String>' is not a subtype of type 'String' in type cast
I don't know what else dart wants from me.
–
–
–
–
I found the answer. I just added .toString() to the _filters List.
this.api.setInterests(token, _filters.toString())
.then((res) {
print(res);
–
You need to add json.encode(data) in body
Add these two header
'Content-type': 'application/json',
'Accept': 'application/json',
Create map of your data
final Map<String, dynamic> data = new Map<String, dynamic>();
data['token'] = token;
data['interests'] = interests;
Call api like this
http.post(url,<br>
body: json.encode(data),
headers: { 'Content-type': 'application/json',
'Accept': 'application/json'},
encoding: encoding)
.then((http.Response response) {
// print(response.toString());
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.