buildCachedDio method

Future<DioBuilderResponse> buildCachedDio(
  1. {bool hasAuth = true,
  2. bool shouldQueue = false,
  3. bool passDomain = false}
)

Implementation

Future<DioBuilderResponse> buildCachedDio({
  bool hasAuth = true,
  bool shouldQueue = false,
  bool passDomain = false,
}) async {
  final DioCacheInterceptor dioCacheManager =
      DioCacheInterceptor(options: cacheOptions);
  final Options dioOptions = cacheOptions.toOptions();
  final String token = await TokenManager().getToken();
  final Dio dio = Dio(
    BaseOptions(
      baseUrl: Environment.currentEnv.baseUrl,
      connectTimeout: const Duration(milliseconds: 15000),
      receiveTimeout: const Duration(milliseconds: 15000),
      headers: hasAuth
          ? {
              'Authorization': 'Bearer $token',
              'Content-Type': 'application/json',
            }
          : {
              'Content-Type': 'application/json',
            },
    ),
  );
  dio.interceptors.add(DioInterceptor(dio));
  dio.interceptors.add(dioCacheManager);
  if (shouldQueue) dio.interceptors.add(QueuedInterceptor());
  return DioBuilderResponse(dio: dio, dioOptions: dioOptions);
}