get abstract method

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. bool showLoader = true,
})

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))),
);

Implementation

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,
  bool showLoader = true,
});