getDio method
Dio
getDio()
Implementation
Dio getDio(){
if(_dio == null){
_dio = Dio();
_dio!.options.baseUrl = _baseUrl;
_dio!.options.connectTimeout = Duration(seconds: 5);
_dio!.interceptors.add(InterceptorsWrapper(
onRequest: onRequestInterceptor,
onResponse: onResponseInterceptor,
onError: onErrorInterceptor,
));
var isOpenProxy = SpUtil.read(SpUtil.IS_OPEN_PROXY,false);
var host = SpUtil.read(SpUtil.PROXY_HOST,'');
var port = SpUtil.read(SpUtil.PROXY_PORT,'');
if(isOpenProxy && '$host'.isNotEmpty && '$port'.isNotEmpty){
_dio!.httpClientAdapter = IOHttpClientAdapter(createHttpClient: () {
final client = HttpClient();
client.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
client.findProxy = (uri) => 'PROXY $host:$port';
return client;
});
}
}
return _dio!;
}