init method
初始化配置
connectTimeout
链接超时时间 5s
receiveTimeout
接收数据的时间 5s
isDebug
是否是debug模式,是会开启日志
Implementation
void init(
String baseUrl, int connectTimeout, int receiveTimeout, bool isDebug) {
// or new Dio with a BaseOptions instance.
var options = BaseOptions(
baseUrl: baseUrl,
connectTimeout: connectTimeout * 1000,
receiveTimeout: receiveTimeout * 1000,
);
_dio = Dio(options);
///
/// 强制信任证书
///
(_dio?.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
(client) {
client.badCertificateCallback = (cert, host, port) {
return true;
};
};
/**
* 开启请求日志
*/
if (isDebug) {
_dio?.interceptors
.add(LogInterceptor(requestBody: true, responseBody: true));
}
}