0 purchases
pq network
pq_network #
基于Dio的一些基础封装
快速设置代理
log格式化,支持开启关闭
mock,可模拟网络请求,返回特定的数据,模拟请求时间
decoder集成,可以在decoder中完成json to Model
使用示例 #
配置Dio,此步骤必须要在网络请求之前
BaseOptions options = BaseOptions(
connectTimeout: 20000,
receiveTimeout: 30000,
sendTimeout: 30000,
baseUrl: "xxxxxx",
headers: {'Content-Type': 'application/json'});
PQNetwork.config(options);
copied to clipboard
请求示例(Mock) #
_get() async {
final path = "https:/xxxxx";
final res = await PQNetwork.get(
path,
mock: true,
mockData: {"msg": "OK", "data": {}, "code": 0},
);
print("xxxxxxxxxx get res $res"); // {"msg": "OK", "data": {}, "code": 0}
}
copied to clipboard
请求示例 (Mock+Decoder) #
_getAndDecoder() async {
final path = "https://xxxxx";
final res = await PQNetwork.get(
path,
decoder: (data) => MockDataEntity.fromJson(data),
mock: true,
mockData: {"msg": "OK", "data": {}, "code": 0},
);
print("xxxxxxxxxx get res $res");
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.