diff --git a/lib/greencode/providers/greencode_item_provider.dart b/lib/greencode/providers/greencode_item_provider.dart new file mode 100644 index 000000000..2cecd0558 --- /dev/null +++ b/lib/greencode/providers/greencode_item_provider.dart @@ -0,0 +1,30 @@ +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:myecl/greencode/class/greencode_item.dart'; +import 'package:myecl/greencode/repositories/greencode_item_repository.dart'; +import 'package:myecl/tools/providers/single_notifier.dart'; + +class GreenCodeItemNotifier extends SingleNotifier { + final GreenCodeItemRepository greencodeItemRepository; + GreenCodeItemNotifier({required this.greencodeItemRepository}) + : super(const AsyncLoading()); + + void loadGreenCodeItembyQRCode(String qrCodeContent) async { + state = const AsyncLoading(); + final item = + await greencodeItemRepository.getGreenCodeItemByQR(qrCodeContent); + state = AsyncData(item); + } + + void setGreenCodeItem(GreenCodeItem i) { + state = AsyncData(i); + } +} + +final greenCodeItemProvider = + StateNotifierProvider>( + (ref) { + final greencodeItemRepository = ref.watch(greencodeItemRepositoryProvider); + return GreenCodeItemNotifier( + greencodeItemRepository: greencodeItemRepository, + ); +}); diff --git a/test/greencode/greencode_item_list_provider_test.dart b/test/greencode/all_greencode_item_list_provider_test.dart similarity index 100% rename from test/greencode/greencode_item_list_provider_test.dart rename to test/greencode/all_greencode_item_list_provider_test.dart