Commit c4da1b6

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-06-27 16:02:16
add delete all notes button
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent f9205db
Changed files (2)
app
lib
l10n
screens
app/lib/l10n/app_en.arb
@@ -552,5 +552,7 @@
   "availableDevices": "Available devices",
   "@availableDevices": {},
   "deleteAllMedicineIntakes": "Delete all medicine intakes",
-  "@deleteAllMedicineIntakes": {}
+  "@deleteAllMedicineIntakes": {},
+  "deleteAllNotes": "Delete all notes",
+  "@deleteAllNotes": {}
 }
app/lib/screens/subsettings/delete_data_screen.dart
@@ -70,7 +70,28 @@ class _DeleteDataScreenState extends State<DeleteDataScreen> {
               }
             },
           ),
-          // FIXME: delete notes
+          ListTile(
+            leading: const Icon(Icons.notes),
+            title: Text(localizations.deleteAllNotes),
+            trailing: const Icon(Icons.delete_forever),
+            onTap: () async {
+              final messanger = ScaffoldMessenger.of(context);
+              if (await showConfirmDeletionDialoge(context, localizations.warnDeletionUnrecoverable)) {
+                final repo = RepositoryProvider.of<NoteRepository>(context);
+                final previousNotes = await repo.get(DateRange.all());
+                for (final note in previousNotes) {
+                  await repo.remove(note);
+                }
+                messanger.showSnackBar(SnackBar(
+                  content: Text(localizations.deletionConfirmed),
+                  action: SnackBarAction(
+                    label: localizations.btnUndo,
+                    onPressed: () => Future.forEach(previousNotes, repo.add),
+                  ),
+                ));
+              }
+            },
+          ),
           ListTile(
             leading: const Icon(Icons.medication),
             title: Text(localizations.deleteAllMedicineIntakes),
@@ -78,7 +99,7 @@ class _DeleteDataScreenState extends State<DeleteDataScreen> {
             onTap: () async {
               if (await showConfirmDeletionDialoge(context, localizations.warnDeletionUnrecoverable)) {
                 final repo = context.read<MedicineIntakeRepository>();
-                final allIntakes = await repo.get(DateRange(start: DateTime.fromMillisecondsSinceEpoch(0), end: DateTime.now()));
+                final allIntakes = await repo.get(DateRange.all());
                 for (final intake in allIntakes) {
                   await repo.remove(intake);
                 }