initNet method

Future<void> initNet({
  1. String? baseUrl,
  2. Dio? dio,
  3. dynamic hookRequest(
    1. 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;
  }
}