client property
Dio
get
client
client Return dio object for http helper
Example:
var partner = PaywayPartner();
var helper = PaywayPartnerClientService(partner);
var dio = helper.getDio();
Implementation
Dio get client {
Dio dio = Dio();
dio.options.baseUrl = partner!.baseApiUrl;
dio.options.connectTimeout = const Duration(seconds: 60);
dio.options.receiveTimeout = const Duration(seconds: 60);
dio.httpClientAdapter = PlatformHttpClientAdapter().clientAdapter();
/// [add interceptors]
dio.interceptors
.add(InterceptorsWrapper(onRequest: (options, handler) async {
options.headers["Accept"] = "application/json";
if(!kIsWeb) {
options.headers["Referer"] = partner?.partnerReferer;
}
return handler.next(options);
}, onResponse: (response, handler) {
// Do something with response data
return handler.next(response); // continue
// If you want to reject the request with a error message,
// you can reject a `DioError` object eg: return `dio.reject(dioError)`
}, onError: (DioException e, handler) {
// Do something with response error
return handler.next(e); //continue
// If you want to resolve the request with some custom data,
// you can resolve a `Response` object eg: return `dio.resolve(response)`.
}));
return dio;
}