getAs<T> method
Future<Either<Failure, T> >
getAs<T>({
- required String endpoint,
- required T parser(
- dynamic data
- Object? data,
- Map<
String, dynamic> ? params, - Duration? receiveTimeout,
- Duration? sendTimeout,
- Map<
String, String> ? headers, - ProgressCallback? onSendProgress,
- ProgressCallback? onReceiveProgress,
- CancelToken? cancelToken,
- bool showLoader = true,
- CachePolicy? cachePolicy,
- Duration? cacheMaxAge,
- bool dedupe = true,
override
get, with the response body deserialized into T.
parser receives response.data — already-decoded JSON, so usually a
Map<String, dynamic> or a List. If it throws, the result is a
Failure with ErrorSource.parseError carrying the raw body in
failure.data; the exception never reaches the caller.
final user = await _api.getAs<User>(
endpoint: '/users/1',
parser: User.fromJson,
);
final users = await _api.getAs<List<User>>(
endpoint: '/users',
parser: listParser(User.fromJson),
);
Implementation
@override
Future<Either<Failure, T>> getAs<T>({
required String endpoint,
required T Function(dynamic data) parser,
Object? data,
Map<String, dynamic>? params,
Duration? receiveTimeout,
Duration? sendTimeout,
Map<String, String>? headers,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
CancelToken? cancelToken,
bool showLoader = true,
CachePolicy? cachePolicy,
Duration? cacheMaxAge,
bool dedupe = true,
}) {
return _respondAs(HttpMethod.get, endpoint, parser,
data: data, params: params, headers: headers);
}