Skip to content

Commit

Permalink
Create separate SharedPreferences provider
Browse files Browse the repository at this point in the history
  • Loading branch information
bizz84 committed Dec 2, 2024
1 parent 3615f9d commit f820a87
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 15 deletions.
7 changes: 4 additions & 3 deletions lib/src/features/onboarding/data/onboarding_repository.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -19,7 +20,7 @@ class OnboardingRepository {
}

@Riverpod(keepAlive: true)
Future<OnboardingRepository> onboardingRepository(
Ref ref) async {
return OnboardingRepository(await SharedPreferences.getInstance());
Future<OnboardingRepository> onboardingRepository(Ref ref) async {
return OnboardingRepository(
ref.watch(sharedPreferencesProvider).requireValue);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/routing/app_router.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions lib/src/routing/app_startup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class AppStartupWidget extends ConsumerWidget {
}
}

/// Widget to show while initialization is in progress
class AppStartupLoadingWidget extends StatelessWidget {
const AppStartupLoadingWidget({super.key});

Expand All @@ -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});
Expand All @@ -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;
}
}
10 changes: 10 additions & 0 deletions lib/src/utils/shared_preferences_provider.dart
Original file line number Diff line number Diff line change
@@ -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> sharedPreferences(Ref ref) {
return SharedPreferences.getInstance();
}
27 changes: 27 additions & 0 deletions lib/src/utils/shared_preferences_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f820a87

Please # to comment.