feat: Add inventory management feature with CRUD operations

- 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.
This commit is contained in:
Nils-Johan Gynther
2026-04-22 08:12:37 +02:00
parent af1a3cd6eb
commit 967121113e
12 changed files with 1301 additions and 0 deletions
@@ -0,0 +1,40 @@
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),
);
});