diff --git a/lib/util/net_util.dart b/lib/util/net_util.dart index cfa526a..57b1715 100644 --- a/lib/util/net_util.dart +++ b/lib/util/net_util.dart @@ -96,7 +96,8 @@ class NetUtil { /// 同步请求 static Future post(String path, - {Map params, Map queryParameters, NetMethod method = NetMethod.POST, bool cache = false, bool showToast = true}) async { + {Map params, Map queryParameters, NetMethod method = NetMethod + .POST, bool cache = false, bool showToast = true, int timeOut = 15000}) async { var paramsData = {'postData': params ?? {}, 'queryParameters': queryParameters ?? {}}; // 根据请求参数,获取缓存的Key @@ -109,11 +110,13 @@ class NetUtil { Response response; try { - Dio dio = await NetUtil.getInstance().dio; + Dio dio = await NetUtil + .getInstance() + .dio; response = await dio.request( path, data: !EmptyUtil.isEmpty(bodyParams) ? bodyParams : null, - options: Options(method: enumToString(method), headers: headParam), + options: Options(method: enumToString(method), headers: headParam, receiveTimeout: timeOut), queryParameters: !EmptyUtil.isEmpty(queryParameters) ? queryParameters : null, ); } on DioError catch (e) { @@ -210,12 +213,12 @@ class NetUtil { /// 异步请求 static void request(String path, {NetMethod method = NetMethod.GET, - Map params, - Map queryParameters, - OnSuccess onSuccess, - OnError onError, - OnCache onCache, - bool showToast = true}) async { + Map params, + Map queryParameters, + OnSuccess onSuccess, + OnError onError, + OnCache onCache, + bool showToast = true,int timeOut=15000}) async { var paramsData = {'postData': params ?? {}, 'queryParameters': queryParameters ?? {}}; // 根据请求参数,获取缓存的Key @@ -227,7 +230,11 @@ class NetUtil { } try { - Map result = await NetUtil.post(path, method: method, params: params, queryParameters: queryParameters, showToast: showToast, cache: onCache != null); + Map result = await NetUtil.post(path, method: method, + params: params, + queryParameters: queryParameters, + showToast: showToast, + cache: onCache != null,timeOut: timeOut); // TODO 解密? if (isSuccess(result)) { if (onSuccess != null) { @@ -239,8 +246,8 @@ class NetUtil { if (onError != null) { onError(!EmptyUtil.isEmpty(result) ? !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_MSG]) - ? result[GlobalConfig.HTTP_RESPONSE_KEY_MSG] - : '未知错误' + ? result[GlobalConfig.HTTP_RESPONSE_KEY_MSG] + : '未知错误' : '未知错误'); } } catch (e) {