initNet method
Future<void>
initNet({
- String? baseUrl,
- Dio? dio,
- dynamic hookRequest(
- RequestOptions options
Implementation
Future<void> initNet(
{String? baseUrl,
Dio? dio,
Function(RequestOptions options)? hookRequest}) async {
if (baseUrl != null && dio == null) {
BaseOptions options = BaseOptions(
baseUrl: baseUrl,
contentType: Headers.jsonContentType,
connectTimeout: const Duration(seconds: CONNECT_TIMEOUT),
receiveTimeout: const Duration(seconds: RECEIVE_TIMEOUT));
_dio = Dio(options);
// add interceptors
_dio?.interceptors.add(DioInterceptor(hookOnRequest: hookRequest));
_dio?.interceptors.add(AwesomeDioInterceptor());
} else if (dio != null) {
_dio = dio;
}
}