BUG: Daily activity completions are not saved to Supabase, progress resets on navigation

Aperta
#217 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@Varadraj75 ci sta già lavorando.

Dal 11/4/2026.

  • #218 di @Varadraj75 — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
dart, flutter, supabase
Ambito
database, mobile

Direzione di ricerca

Riproduci il flusso di navigazione, quindi segui toggleTaskCompletion() in task_provider.dart e le relative chiamate a updateActivityCompletion(). Leggi daily_activities_screen.dart, in particolare il fallback commentato e il comportamento all’uscita dalla schermata. È completato quando le modifiche alle caselle di controllo raggiungono la tabella daily_activity_logs e rimangono selezionate dopo la navigazione, il cambio di data o il riavvio dell’app.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Is there an existing issue for this?
  • I have searched the existing issues
What happened?

📌 Issue Overview

When a patient checks off daily activities as completed, the checkbox toggles only update local in-memory state and are never written to Supabase. All progress is silently lost the moment the user navigates away, switches dates, or restarts the app.

Three interacting defects cause this:

  1. toggleTaskCompletion() in task_provider.dart only mutates _allTasks in memory and calls notifyListeners(). It never calls updateActivityCompletion(). The method is marked async but contains no await and is effectively synchronous.

  2. The only fallback save path was explicitly commented out in daily_activities_screen.dart:

   // context.read().updateActivityInBackground(); // TODO: Uncomment this when the backend is ready

The method updateActivityInBackground does not even exist on TaskProvider, it was never implemented.

  1. updateActivityCompletion() is only called inside setSelectedDate(), meaning the only time data is saved is when the user switches the date picker to a different day. If the user checks activities and presses back without changing dates, nothing is saved. This also introduces a race condition since getTodayActivities() is called immediately
    after, potentially overwriting unsaved state with a fresh DB read.

The screen has no PopScope, no WillPopScope, no AppLifecycleObserver, and no
dispose() save logic. There is zero mechanism to flush pending changes on any form of exit.

🔍 Steps to Reproduce

  1. Log in as a patient who has daily activities assigned
  2. Navigate to Home → Daily Activities
  3. Wait for activities to load
  4. Check 2 or more activity checkboxes - observe they toggle visually
  5. Press the back arrow to return to home
  6. Navigate back to Daily Activities
  7. All checkboxes are unchecked, all progress is lost
  8. Alternatively: check activities, kill and restart the app, same result

🎯 Expected Behavior

Each checkbox toggle should persist the is_completed state to the daily_activity_logs table in Supabase immediately or on a short debounce. Navigating away and back should restore the previously checked state from the database.

🚨 Actual Behavior

No Supabase call is made on checkbox toggle. The in-memory state is discarded on navigation. The daily_activity_logs table never reflects actual patient completions, which means:

  • The Reports screen always shows activities as incomplete
  • Therapists see 0% completion for activities the patient believes they completed
  • Patient therapy progress data is silently corrupted

📷 Screenshot

Not applicable. The bug is in data not written to Supabase, not visible in the UI.

💡 Suggested Improvements

task_provider.dart:

  • Add a Timer? _debounceTimer field
  • In toggleTaskCompletion(), after mutating _allTasks, start a 1.5s debounce timer that calls updateActivityCompletion(_allTasks)
  • Add a Future<void> saveAndFlush() method that cancels the timer and immediately
    awaits updateActivityCompletion(_allTasks) for use on screen exit

daily_activities_screen.dart:

  • Wrap the Scaffold in a PopScope with onPopInvokedWithResult calling taskProvider.saveAndFlush() before allowing pop
  • Add WidgetsBindingObserver and implement didChangeAppLifecycleState to call saveAndFlush() on AppLifecycleState.paused
  • Remove the commented-out updateActivityInBackground line

supabase_patient_repository.dart:

  • No changes needed. updateActivityCompletion() is correctly implemented, it is just never called from the right place
Record
  • I agree to follow this project's Code of Conduct
  • I want to work on this issue
Lingua principale
Dart
Stelle
30
Fork
49
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di AOSSIE-Org/NeuroTrack

Tutte le issue di AOSSIE-Org/NeuroTrack

Issue simili

Altre issue su Dart

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.