get<T> method

  1. @override
Future<Either<BaseException, T>> get<T>(
  1. String path, {
  2. Map<String, dynamic>? queryParameters,
  3. required dynamic mapper(
    1. dynamic json
    ),
  4. Options? options,
  5. VoidDataFunction<double>? onProgress,
  6. List<JsonFieldAliasModel> jsonSchemas = const [],
  7. RequestEnum type = .get,
  8. void onAsync(
    1. Either<BaseException, T> result
    )?,
  9. void onSync(
    1. Either<BaseException, T> result
    )?,
  10. SyncApiRequestScope? scope,
})
override

Implementation

@override
Future<Either<BaseException, T>> get<T>(
  String path, {
  Map<String, dynamic>? queryParameters,
  required Function(dynamic json) mapper,
  Options? options,
  VoidDataFunction<double>? onProgress,
  List<JsonFieldAliasModel> jsonSchemas = const [],
  RequestEnum type = .get,
  void Function(Either<BaseException, T> result)? onAsync,
  void Function(Either<BaseException, T> result)? onSync,
  SyncApiRequestScope? scope,
}) async {
  final context = _SyncApiLoadContext<T>(
    mapper: mapper,
    onSync: onSync,
    onAsync: onAsync,
    scope: scope ?? _scopeFor(type, path.split('?').first.split('#').first),
  );

  try {
    final request = _SyncApiRequest(
      path: path,
      namespace: getUserId ?? '',
      method: type,
      queryParameters: type == .get ? queryParameters : null,
      body: type == .post ? queryParameters : null,
      options: options,
      onProgress: onProgress,
    );

    await _loadFromCache(
      context,
      request,
    );

    if (!context.isCurrent) {
      return Left(
        SyncApiException(
          detail: SeedKitModuleApiLocale.current.exception_sync_api_client,
        ),
      );
    }

    return await _loadFromNetwork(
      context,
      request,
    );
  } catch (error, stackTrace) {
    final result = ErrorHandler.fromError<T>(
      error,
      stackTrace: stackTrace,
    );

    context.deliverNetwork(result);

    return result;
  }
}