【发布时间】:2022-01-05 13:31:11
【问题描述】:
E/flutter (19556): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] 未处理的异常:“位置”类型不是“字符串”类型的子类型 位置是位置对象。
var req = http.MultipartRequest('POST', uri);
req.fields['category'] = _categoryTEC;
req.fields['title'] = _titleTEC.text;
req.fields['price'] = _priceTEC.text;
req.fields['description'] = _descriptionTEC.text;
req.fields['location'] = location; //position(lcation) is an object.
req.headers.addAll(authHeadToken);
req.files.add(await http.MultipartFile.fromPath(
'adphoto', images!.first.path.toString()));
var res = await (req.send());```
【问题讨论】:
-
好的,我发现了一个 hack,我将位置作为字符串发送 req.fields['location'] = jsonEncode(location); 因为 dart 在使用时将其转换为字符串jsonEncode(location) 并在后端解析为 JSON.parse(location); 以使其成为 json。 它对我有用虽然仍然需要答案并且将不胜感激。
标签: flutter http dart multipart