diff --git a/app/lib/observers/midnight_observer.dart b/app/lib/observers/midnight_observer.dart index b1050f0..b5acc03 100644 --- a/app/lib/observers/midnight_observer.dart +++ b/app/lib/observers/midnight_observer.dart @@ -12,11 +12,16 @@ void initializeMidnightObserver(WidgetRef ref) { final authStream = ref.read(authRepositoryProvider).authStateChangesStream; StreamSubscription? sub; - authStream.listen((newUser) { - sub?.cancel(); + authStream.listen((newUser) async { // Add async to allow use of await + - if (newUser != null) { - sub = currentDayStream.listen((DateTime currentDay) async { + while (newUser == null) { + await Future.delayed(Duration.zero); + } + + if (newUser != null) { + sub?.cancel(); + sub = currentDayStream.listen((DateTime currentDay) async { final progressRepository = ref.read(progressRepositoryProvider); List allProgressObjs = await progressRepository.readAllProgressions(newUser.uid);