【发布时间】:2021-01-05 09:27:30
【问题描述】:
我在多选中发送列表类型的发布请求。我无法制作 json.encode。我的代码在这里。
型号
import 'dart:convert';
class FabricType {
String name;
String apiName;
int value;
String uuid;
FabricType({this.name, this.apiName,this.value,this.uuid});
factory FabricType.fromJson(Map<String, dynamic> json) {
return FabricType(
name: json['name'],
apiName: json['apiName'],
value: json['value'],
uuid: json['uuid'],
);
}
Map toMap() {
var map = new Map<String, dynamic>();
map["name"] = name;
map["apiName"] = apiName;
map["value"] = value;
map["uuid"] = uuid;
return map;
}
}
对于
List<FabricType> fabricList = List();
subContentList(List subContentList, List selectedUUid) {
fabricList.clear();
for (int i = 0; i < selectedUUid.length;i++) {
fabricType = new FabricType();
fabricType.uuid = selectedUUid[i].toString();
fabricType.name = "test";
fabricType.apiName = "colorTypes";
fabricList.add(fabricType);
}
}
发布请求
Response res = await http.post(
BaseApi + EndPoint,
headers: Header().header,
body:json.encode(fabricList) //Bug Here
);
print(res.body);
String statusCode = res.statusCode.toString();
print("Ad Sub Content Status Code: " + statusCode);
return res;
错误信息
I/flutter (15808): [Instance of 'FabricType', Instance of 'FabricType']
问题是“编码”;问题是什么?我该怎么办?
【问题讨论】:
标签: flutter flutter-layout flutter-dependencies flutter-test