main
1import 'package:blood_pressure_app/components/confirm_deletion_dialoge.dart';
2import 'package:blood_pressure_app/model/storage/export_columns_store.dart';
3import 'package:blood_pressure_app/model/storage/storage.dart';
4import 'package:flutter/material.dart';
5import 'package:flutter_bloc/flutter_bloc.dart';
6import 'package:blood_pressure_app/l10n/app_localizations.dart';
7import 'package:health_data_store/health_data_store.dart';
8
9/// Screen that allows mass deleting data entered in the app.
10class DeleteDataScreen extends StatefulWidget {
11 /// Create screen that allows mass data deletion.
12 const DeleteDataScreen({super.key});
13
14 @override
15 State<DeleteDataScreen> createState() => _DeleteDataScreenState();
16}
17
18class _DeleteDataScreenState extends State<DeleteDataScreen> {
19 @override
20 Widget build(BuildContext context) {
21 final localizations = AppLocalizations.of(context)!;
22 return Scaffold(
23 appBar: AppBar(
24 title: Text(localizations.delete),
25 leading: IconButton(
26 icon: const Icon(Icons.arrow_back),
27 onPressed: () => Navigator.pop(context),
28 ),
29 ),
30 body: ListView(
31 children: [
32 ListTile(
33 leading: const Icon(Icons.settings),
34 title: Text(localizations.deleteAllSettings),
35 trailing: const Icon(Icons.delete_forever),
36 onTap: () async {
37 final messanger = ScaffoldMessenger.of(context);
38 if (await showConfirmDeletionDialoge(context, localizations.warnDeletionUnrecoverable)) {
39 context.read<Settings>().reset();
40 context.read<ExportSettings>().reset();
41 context.read<CsvExportSettings>().reset();
42 context.read<PdfExportSettings>().reset();
43 context.read<IntervalStoreManager>().reset();
44 context.read<ExportColumnsManager>().reset();
45 messanger.showSnackBar(SnackBar(
46 content: Text(localizations.deletionConfirmed),
47 ));
48 }
49 },
50 ),
51 ListTile(
52 leading: const Icon(Icons.timeline),
53 title: Text(localizations.deleteAllMeasurements),
54 trailing: const Icon(Icons.delete_forever),
55 onTap: () async {
56 final messanger = ScaffoldMessenger.of(context);
57 if (await showConfirmDeletionDialoge(context, localizations.warnDeletionUnrecoverable)) {
58 final repo = RepositoryProvider.of<BloodPressureRepository>(context);
59 final previousRecords = await repo.get(DateRange.all());
60 for (final record in previousRecords) {
61 await repo.remove(record);
62 }
63 messanger.showSnackBar(SnackBar(
64 content: Text(localizations.deletionConfirmed),
65 action: SnackBarAction(
66 label: localizations.btnUndo,
67 onPressed: () => Future.forEach(previousRecords, repo.add),
68 ),
69 ));
70 }
71 },
72 ),
73 ListTile(
74 leading: const Icon(Icons.notes),
75 title: Text(localizations.deleteAllNotes),
76 trailing: const Icon(Icons.delete_forever),
77 onTap: () async {
78 final messanger = ScaffoldMessenger.of(context);
79 if (await showConfirmDeletionDialoge(context, localizations.warnDeletionUnrecoverable)) {
80 final repo = RepositoryProvider.of<NoteRepository>(context);
81 final previousNotes = await repo.get(DateRange.all());
82 for (final note in previousNotes) {
83 await repo.remove(note);
84 }
85 messanger.showSnackBar(SnackBar(
86 content: Text(localizations.deletionConfirmed),
87 action: SnackBarAction(
88 label: localizations.btnUndo,
89 onPressed: () => Future.forEach(previousNotes, repo.add),
90 ),
91 ));
92 }
93 },
94 ),
95 ListTile(
96 leading: const Icon(Icons.medication),
97 title: Text(localizations.deleteAllMedicineIntakes),
98 trailing: const Icon(Icons.delete_forever),
99 onTap: () async {
100 if (await showConfirmDeletionDialoge(context, localizations.warnDeletionUnrecoverable)) {
101 final repo = context.read<MedicineIntakeRepository>();
102 final allIntakes = await repo.get(DateRange.all());
103 for (final intake in allIntakes) {
104 await repo.remove(intake);
105 }
106 final messanger = ScaffoldMessenger.of(context);
107 messanger.showSnackBar(SnackBar(
108 content: Text(localizations.deletionConfirmed),
109 ));
110 }
111 },
112 ),
113 ],
114 ),
115 );
116 }
117}