Skip to content
Open
13 changes: 9 additions & 4 deletions app/lib/observers/midnight_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
philippkolbe marked this conversation as resolved.


if (newUser != null) {
sub = currentDayStream.listen((DateTime currentDay) async {
while (newUser == null) {
await Future.delayed(Duration.zero);
}

if (newUser != null) {
Comment thread
philippkolbe marked this conversation as resolved.
sub?.cancel();
sub = currentDayStream.listen((DateTime currentDay) async {
final progressRepository = ref.read(progressRepositoryProvider);

List<ProgressObj> allProgressObjs = await progressRepository.readAllProgressions(newUser.uid);
Expand Down