get method

  1. @override
Future<Either<Failure, Response>> get({
  1. required String endpoint,
  2. Object? data,
  3. Map<String, dynamic>? params,
  4. Duration? receiveTimeout,
  5. Duration? sendTimeout,
  6. Map<String, String>? headers,
  7. ProgressCallback? onSendProgress,
  8. ProgressCallback? onReceiveProgress,
  9. CancelToken? cancelToken,
  10. ResponseType? responseType,
  11. String? tag,
  12. bool showLoader = true,
  13. bool dedupe = true,
})
override

Sends a GET request to endpoint.

Use for fetching resources that don't require a request body. Query parameters go in params.

Returns Right(Response) on success, Left(Failure) on any error (network, timeout, 4xx/5xx, no internet).

Example:

final result = await _api.get(
  endpoint: '/users',
  params: {'page': 1, 'limit': 20},
);

result.fold(
  (failure) => emit(ErrorState(failure.message)),
  (response) => emit(LoadedState(UserListModel.fromJson(response.data))),
);

De-duplication. Two identical GETs in flight at the same time share one network call by default. Pass dedupe: false to force a separate request. Automatically skipped when you supply your own cancelToken or a tag, since cancelling one caller must not cancel the other, and when you pass a progress callback, which only one caller's request can drive.

Implementation

@override
Future<Either<Failure, Response>> get({
  required String endpoint,
  Object? data,
  Map<String, dynamic>? params,
  Duration? receiveTimeout,
  Duration? sendTimeout,
  Map<String, String>? headers,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
  CancelToken? cancelToken,
  ResponseType? responseType,
  String? tag,
  bool showLoader = true,
  bool dedupe = true,
}) {
  return _respond(
    HttpMethod.get,
    endpoint,
    data: data,
    params: params,
    headers: headers,
    tag: tag,
    cancelToken: cancelToken,
  );
}