FlutterNetwork constructor

FlutterNetwork({
  1. required String baseUrl,
  2. Future<String?> tokenCallback()?,
  3. VoidCallback? onUnAuthorizedError,
  4. CacheOptions? cacheOptions,
  5. RetryInterceptor? retryInterceptor,
  6. int connectionTimeout = 30000,
  7. int receiveTimeout = 30000,
})

Implementation

factory FlutterNetwork({
  required String baseUrl,
  Future<String?> Function()? tokenCallback,
  VoidCallback? onUnAuthorizedError,
  CacheOptions? cacheOptions,
  RetryInterceptor? retryInterceptor,
  int connectionTimeout = 30000,
  int receiveTimeout = 30000,
}) {
  _instance.baseUrl = baseUrl;
  _instance.tokenCallback = tokenCallback;
  _instance.onUnAuthorizedError = onUnAuthorizedError ?? () {};
  _instance.connectionTimeout = connectionTimeout;
  _instance.receiveTimeout = receiveTimeout;
  _instance.cacheOptions = cacheOptions;
  _instance.retryInterceptor = retryInterceptor;

  BaseOptions options = BaseOptions(
    baseUrl: baseUrl,
    connectTimeout: Duration(milliseconds: connectionTimeout),
    receiveTimeout: Duration(milliseconds: receiveTimeout),
  );

  _instance._dio = Dio(options);
  return _instance;
}