Skip to content

Commit

Permalink
Add await ref.watch(sharedPreferencesProvider.future) to prevent Asyn…
Browse files Browse the repository at this point in the history
…cValue error during app startup
  • Loading branch information
bizz84 committed Dec 18, 2024
1 parent 80fdc7f commit 67b81e7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/src/routing/app_startup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:starter_architecture_flutter_firebase/src/constants/app_sizes.dart';
import 'package:starter_architecture_flutter_firebase/src/features/onboarding/data/onboarding_repository.dart';
import 'package:starter_architecture_flutter_firebase/src/utils/shared_preferences_provider.dart';

part 'app_startup.g.dart';

Expand All @@ -11,12 +12,14 @@ part 'app_startup.g.dart';
Future<void> appStartup(Ref ref) async {
ref.onDispose(() {
// ensure dependent providers are disposed as well
ref.invalidate(sharedPreferencesProvider);
ref.invalidate(onboardingRepositoryProvider);
});
// Uncomment this to test that URL-based navigation and deep linking works
// even when there's a delay in the app startup logic
// await Future.delayed(Duration(seconds: 1));
// await for all initialization code to be complete before returning
await ref.watch(sharedPreferencesProvider.future);
await ref.watch(onboardingRepositoryProvider.future);
}

Expand Down

0 comments on commit 67b81e7

Please sign in to comment.