Skip to content

Commit

Permalink
fix(app): close app after data deletion to ensure proper loading of h…
Browse files Browse the repository at this point in the history
…ive when restarted
  • Loading branch information
tamslo committed Jan 21, 2025
1 parent 72ce9d1 commit d75bbd0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
10 changes: 7 additions & 3 deletions app/lib/common/utilities/hive_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ Future<List<int>> retrieveExistingOrGenerateKey() async {
return base64Url.decode(key!);
}

Future<void> deleteAllAppData() async {
await _deleteCacheDir();
await _deleteAppDir();
Future<void> unsetAllData() async {
await UserData.erase();
await MetaData.erase();
await DrugsWithGuidelines.erase();
}

Future<void> deleteAllAppData() async {
await unsetAllData();
await _deleteCacheDir();
await _deleteAppDir();
}

// The folders themselves cannot be deleted on iOS, therefore delete all content
// inside the folders
void _deleteFolderContent(Directory directory) {
Expand Down
6 changes: 5 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,11 @@
"@more_page_delete_data": {},
"more_page_delete_data_text": "Are you sure that you want to delete all app data? This also includes your genetic data and will reset the app.",
"@more_page_delete_data_text": {},
"more_page_delete_data_additional_text": "Your genetic data will be deleted and it might not be possible to import it again.",
"more_page_delete_data_additional_text": "Your genetic data will be deleted from your phone and it might not be possible to import it again.\n\nAfter deleting the data, you will be asked to close the app.",
"delete_data_restart_title": "All data deleted",
"@delete_data_restart_title": {},
"delete_data_restart_text": "Please close the app now. To setup PharMe again, please restart the app.",
"@delete_data_restart_text": {},
"@more_page_delete_data_additional_text": {},
"more_page_delete_data_confirmation": "I understand the consequences and want to delete all app data",
"@more_page_delete_data_confirmation": {},
Expand Down
24 changes: 23 additions & 1 deletion app/lib/more/pages/more.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import '../../common/module.dart';
import '../../common/utilities/hive_utils.dart';

Expand Down Expand Up @@ -134,7 +136,27 @@ class DeleteDataDialog extends HookWidget {
? () async {
await deleteAllAppData();
// ignore: use_build_context_synchronously
await overwriteRoutes(context, nextPage: LoginRoute());
await context.router.root.maybePop();
// ignore: use_build_context_synchronously
await showAdaptiveDialog(
// ignore: use_build_context_synchronously
context: context,
builder: (context) => DialogWrapper(
title: context.l10n.delete_data_restart_title,
content: Column(
children: [
SizedBox(height: PharMeTheme.smallSpace),
Text(context.l10n.delete_data_restart_text),
],
),
actions: [
DialogAction(
text: context.l10n.error_close_app,
onPressed: () => exit(0),
),
],
),
);
}
: null,
text: context.l10n.action_continue,
Expand Down

0 comments on commit d75bbd0

Please sign in to comment.