fake_store_api_client 1.0.2
fake_store_api_client: ^1.0.2 copied to clipboard
Cliente Flutter para la Fake Store API con Clean Architecture y manejo funcional de errores.
Fake Store API Client #
Cliente Flutter para Fake Store API con manejo funcional de errores.
Instalación #
dependencies:
fake_store_api_client: ^1.0.2
O ejecuta:
flutter pub add fake_store_api_client
Uso #
import 'package:fake_store_api_client/fake_store_api_client.dart';
final repository = FakeStoreApi.createRepository();
final result = await repository.getAllProducts();
result.fold(
(failure) => print('Error: ${failure.message}'),
(products) => print('${products.length} productos'),
);
API #
| Método | Retorno |
|---|---|
getAllProducts() |
Either<Failure, List<Product>> |
getProductById(id) |
Either<Failure, Product> |
getAllCategories() |
Either<Failure, List<String>> |
getProductsByCategory(cat) |
Either<Failure, List<Product>> |
Manejo de Errores #
switch (result) {
case Left(value: ConnectionFailure()): // Sin conexión
case Left(value: ServerFailure()): // Error 5xx
case Left(value: NotFoundFailure()): // Error 404
case Left(value: InvalidRequestFailure()): // Error 4xx
case Right(value: final data): // Éxito
}
Ejemplo #
cd example && flutter run
Licencia #
MIT