return json as T;
}
}
}
BaseEntity:
class BaseEntity {
int code;
String message;
T data;
BaseEntity({this.code, this.message, this.data});
factory BaseEntity.fromJson(json) {
return BaseEntity(
code: json[“code”],
message: json[“msg”],
// data值需要经过工厂转换为我们传进来的类型
data: EntityFactory.generateOBJ(json[“data”]),
);
}
}
BaseListEntity:
class BaseListEntity {
int code;
String message;
List data;
BaseListEntity({this.code, this.message, this.data});
factory BaseListEntity.fromJson(json) {
List mData = List();
if (json[‘data’] != null) {
//遍历data并转换为我们传进来的类型
(json[‘data’] as List).forEach((v) {
mData.add(EntityFactory.generateOBJ(v));
});
}
return BaseListEntity(
code: json[“code”],
message: json[“msg”],
data: mData,
);
} }
ErrorEntity:
class ErrorEntity {
int code;
String message;
ErrorEntity({this.code, this.message});
}
NWApi:
class NWApi {
static final baseApi = “https://easy-mock.bookset.io/mock/5dfae67d4946c20a50841fa7/example/”;
static final loginPath = “user/login”;//接口返回:{“code”: int, “message”: “String”, “data”: {“account”: “String”, “password”: “String”}}
static final queryListPath = “/query/list”;//接口返回:{“code”: ing, “message”: “String”, “data”: [int, int, String, int, String, int]}
static final queryListJsonPath = “/query/listjson”;//接口返回:{“code”: int, “message”: “String”, “data”: [{“account”: “String”, “password”: “String”}, {“account”: “String”, “password”: “String”}]}
}
NWMethod:
enum NWMethod {
GET,
POST,
DELETE,
PUT
}
//使用:NWMethodValues[NWMethod.POST]
const NWMethodValues = {
NWMethod.GET: “get”,
NWMethod.POST: “post”,
NWMethod.DELETE: “delete”,
NWMethod.PUT: “put”
};