967121113e
- Implemented inventory screen to display items with details. - Added create, edit, and consume inventory screens for managing items. - Introduced consumption history screen to track item usage. - Created inventory repository and providers for API interactions. - Enhanced routing to include inventory-related paths. - Added necessary models for inventory items and consumption history. - Integrated error handling and loading states for better user experience.
41 lines
1.3 KiB
Dart
41 lines
1.3 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../../core/api/api_providers.dart';
|
|
import '../../../core/api/guarded_api_call.dart';
|
|
import '../../auth/data/auth_providers.dart';
|
|
import '../domain/inventory_item.dart';
|
|
import '../domain/inventory_consumption.dart';
|
|
import 'inventory_repository.dart';
|
|
|
|
final inventoryRepositoryProvider = Provider<InventoryRepository>((ref) {
|
|
return InventoryRepository(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final inventoryProvider = FutureProvider<List<InventoryItem>>((ref) async {
|
|
final token = await ref.watch(authStateProvider.future);
|
|
return guardedApiCall(
|
|
ref,
|
|
() => ref.read(inventoryRepositoryProvider).fetchInventory(token: token),
|
|
);
|
|
});
|
|
|
|
final inventoryDetailProvider =
|
|
FutureProvider.family<InventoryItem, int>((ref, id) async {
|
|
final token = await ref.watch(authStateProvider.future);
|
|
return guardedApiCall(
|
|
ref,
|
|
() => ref.read(inventoryRepositoryProvider).fetchInventoryItem(id, token: token),
|
|
);
|
|
});
|
|
|
|
final consumptionHistoryProvider =
|
|
FutureProvider.family<List<InventoryConsumption>, int>((ref, id) async {
|
|
final token = await ref.watch(authStateProvider.future);
|
|
return guardedApiCall(
|
|
ref,
|
|
() => ref
|
|
.read(inventoryRepositoryProvider)
|
|
.fetchConsumptionHistory(id, token: token),
|
|
);
|
|
});
|