get<T> method
Future<Either<BaseException, T> >
get<T>(
- String path, {
- Map<
String, dynamic> ? queryParameters, - required dynamic mapper(
- dynamic json
- Options? options,
- VoidDataFunction<
double> ? onProgress, - List<
JsonFieldAliasModel> jsonSchemas = const [], - RequestEnum type = .get,
- void onAsync(
- Either<
BaseException, T> result
- Either<
- void onSync(
- Either<
BaseException, T> result
- Either<
- 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;
}
}