client property
Dio
get
client
client Return dio object for http helper
Example:
var merchant = ABAMerchant();
var helper = ABAClientService(merchant);
var dio = helper.getDio();
Implementation
Dio get client {
Dio dio = Dio();
dio.options.baseUrl = merchant!.baseApiUrl!;
dio.options.connectTimeout = 60 * 1000; //60 seconds
dio.options.receiveTimeout = 60 * 1000; //60 seconds
/// [add interceptors]
dio.interceptors
.add(InterceptorsWrapper(onRequest: (options, handler) async {
if (!kIsWeb) {
options.headers["Referer"] = merchant!.refererDomain;
}
options.headers["Accept"] = "application/json";
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: (DioError 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;
}