diff --git a/lib/src/features/onboarding/data/onboarding_repository.dart b/lib/src/features/onboarding/data/onboarding_repository.dart index d7fb71d9..11b12569 100644 --- a/lib/src/features/onboarding/data/onboarding_repository.dart +++ b/lib/src/features/onboarding/data/onboarding_repository.dart @@ -1,6 +1,7 @@ import 'package:riverpod/riverpod.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:starter_architecture_flutter_firebase/src/utils/shared_preferences_provider.dart'; part 'onboarding_repository.g.dart'; @@ -19,7 +20,7 @@ class OnboardingRepository { } @Riverpod(keepAlive: true) -Future onboardingRepository( - Ref ref) async { - return OnboardingRepository(await SharedPreferences.getInstance()); +Future onboardingRepository(Ref ref) async { + return OnboardingRepository( + ref.watch(sharedPreferencesProvider).requireValue); } diff --git a/lib/src/features/onboarding/data/onboarding_repository.g.dart b/lib/src/features/onboarding/data/onboarding_repository.g.dart index cdd0e058..2dca7ca3 100644 --- a/lib/src/features/onboarding/data/onboarding_repository.g.dart +++ b/lib/src/features/onboarding/data/onboarding_repository.g.dart @@ -7,7 +7,7 @@ part of 'onboarding_repository.dart'; // ************************************************************************** String _$onboardingRepositoryHash() => - r'82b5e5e6874b171be6d6149d9d6c6c4f2f456afd'; + r'b3d2bcb49877fe1de659afaf4683aca9fccf5b3e'; /// See also [onboardingRepository]. @ProviderFor(onboardingRepository) diff --git a/lib/src/routing/app_router.g.dart b/lib/src/routing/app_router.g.dart index 9e8faa5f..2669284f 100644 --- a/lib/src/routing/app_router.g.dart +++ b/lib/src/routing/app_router.g.dart @@ -6,7 +6,7 @@ part of 'app_router.dart'; // RiverpodGenerator // ************************************************************************** -String _$goRouterHash() => r'ef0a5ec8f23a0968d458bf792d45db5cd2103913'; +String _$goRouterHash() => r'bdb6fbb3c1421654e085ee95c8071b4996f3f578'; /// See also [goRouter]. @ProviderFor(goRouter) diff --git a/lib/src/routing/app_startup.dart b/lib/src/routing/app_startup.dart index fa413ec4..e3639802 100644 --- a/lib/src/routing/app_startup.dart +++ b/lib/src/routing/app_startup.dart @@ -39,6 +39,7 @@ class AppStartupWidget extends ConsumerWidget { } } +/// Widget to show while initialization is in progress class AppStartupLoadingWidget extends StatelessWidget { const AppStartupLoadingWidget({super.key}); @@ -53,6 +54,7 @@ class AppStartupLoadingWidget extends StatelessWidget { } } +/// Widget to show if initialization fails class AppStartupErrorWidget extends StatelessWidget { const AppStartupErrorWidget( {super.key, required this.message, required this.onRetry}); @@ -79,13 +81,3 @@ class AppStartupErrorWidget extends StatelessWidget { ); } } - -class AppStartupDataWidget extends StatelessWidget { - const AppStartupDataWidget({super.key, required this.child}); - final Widget child; - - @override - Widget build(BuildContext context) { - return child; - } -} diff --git a/lib/src/utils/shared_preferences_provider.dart b/lib/src/utils/shared_preferences_provider.dart new file mode 100644 index 00000000..3001c478 --- /dev/null +++ b/lib/src/utils/shared_preferences_provider.dart @@ -0,0 +1,10 @@ +import 'package:riverpod/riverpod.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +part 'shared_preferences_provider.g.dart'; + +@Riverpod(keepAlive: true) +Future sharedPreferences(Ref ref) { + return SharedPreferences.getInstance(); +} diff --git a/lib/src/utils/shared_preferences_provider.g.dart b/lib/src/utils/shared_preferences_provider.g.dart new file mode 100644 index 00000000..d24abe40 --- /dev/null +++ b/lib/src/utils/shared_preferences_provider.g.dart @@ -0,0 +1,27 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'shared_preferences_provider.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +String _$sharedPreferencesHash() => r'48e60558ea6530114ea20ea03e69b9fb339ab129'; + +/// See also [sharedPreferences]. +@ProviderFor(sharedPreferences) +final sharedPreferencesProvider = FutureProvider.internal( + sharedPreferences, + name: r'sharedPreferencesProvider', + debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') + ? null + : _$sharedPreferencesHash, + dependencies: null, + allTransitiveDependencies: null, +); + +@Deprecated('Will be removed in 3.0. Use Ref instead') +// ignore: unused_element +typedef SharedPreferencesRef = FutureProviderRef; +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package