flutter相关git
www.flutterj.com/nCoV-2019.a…程序员
IOS: 拉下代码直接跑便可github
这段时间肺炎比较严重,你们记得戴口罩json
你们好,我又来蹭热点了。微信
1.26日02:00看到了:markdown
从而有了这篇文章。架构
我不是什么专业人士,也没法贡献医疗力量,只能尽我所能看是否能为这件事作一点点的贡献。app
还有就是始终没法劝动父母戴口罩,我爸今天还打牌到凌晨2点左右才回来,他去以前我都跟他约定好了,我不去网吧上网了,他也别去打牌了,并讲述了此次疫情的重要性, 无果。框架
App内全部资讯来自人民日报和丁香医生,官方实时动态更新,经验证。async
本次App研发主要采用dart语言,flutter框架,MVVM架构设计,采用上文提供的接口进行开发,代码很是简洁可观,注释明确。
![]() |
![]() |
![]() |
![]() |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
封装了请求Model和ViewModel;
View层暂无,因此还不算完整,待更新
// 请求计数
var _id = 0;
/* * 请求类型枚举 * */
enum RequestType { GET, POST }
class ReqModel {
///链接超时时间为5秒
static const int connectTimeOut = 5 * 1000;
///响应超时时间为7秒
static const int receiveTimeOut = 7 * 1000;
// 请求url路径
String url() => null;
// 请求参数
Map params() => {};
/* * get请求 * */
Future<dynamic> get() async {
return this._request(
url: url(),
method: RequestType.GET,
params: params(),
);
}
/* * post请求 * */
Future post() async {
return this._request(
url: url(),
method: RequestType.POST,
params: params(),
);
}
/* * post请求-文件上传方式 * */
Future postUpload(
ProgressCallback progressCallBack, {
FormData formData,
}) async {
return this._request(
url: url(),
method: RequestType.POST,
formData: formData,
progressCallBack: progressCallBack,
params: params(),
);
}
/* * 请求方法 * */
Future _request({
String url,
RequestType method,
Map params,
FormData formData,
ProgressCallback progressCallBack,
}) async {
Dio _client;
final httpUrl = '$reqUrl$url';
if (_client == null) {
BaseOptions options = new BaseOptions();
options.connectTimeout = connectTimeOut;
options.receiveTimeout = receiveTimeOut;
options.headers = const {'Content-Type': 'application/json'};
options.baseUrl = reqUrl;
_client = new Dio(options);
}
final id = _id++;
int statusCode;
try {
Response response;
if (method == RequestType.GET) {
///组合GET请求的参数
if (mapNoEmpty(params)) {
response = await _client.get(
url,
queryParameters: params,
);
} else {
response = await _client.get(
url,
);
}
} else {
if (mapNoEmpty(params) && formData.isNotEmpty) {
response = await _client.post(
url,
data: formData ?? params,
onSendProgress: progressCallBack,
);
} else {
response = await _client.post(
url,
);
}
}
statusCode = response.statusCode;
if (response != null) {
print('HTTP_REQUEST_URL::[$id]::$httpUrl');
if (mapNoEmpty(params)) print('HTTP_REQUEST_BODY::[$id]::$params');
print('HTTP_RESPONSE_BODY::[$id]::${json.encode(response.data)}');
return response.data;
}
///处理错误部分
if (statusCode < 0) {
return _handError(statusCode);
}
} catch (e) {
return _handError(statusCode);
}
}
///处理异常
static Future _handError(int statusCode) {
String errorMsg = 'Network request error';
Map errorMap = {"errorMsg": errorMsg, "errorCode": statusCode};
print("HTTP_RESPONSE_ERROR::$errorMsg code:$statusCode");
return Future.value(errorMap);
}
}
复制代码
带参数例子:
来自普通程序员, 连接:juejin.im/post/5e2c6a…
项目在不断更新,目前架构和请求等数据处理方式已封装完毕。
正在进行View层和推送的开发。
接口做者(普通程序员)也在不段优化和更新,在此致敬!
若是你们有好的意见或者有好的设计图的话能够群内找我。
Flutter交流QQ群:874592746
Flutter交流微信群: