Skip to content

Commit 7e8c8f2

Browse files
committed
fix: Fixed app exiting on iOS.
1 parent f3ad973 commit 7e8c8f2

File tree

3 files changed

+62
-19
lines changed

3 files changed

+62
-19
lines changed

lib/i18n/en/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@
167167
},
168168
"doneDialog": {
169169
"title": "Data deleted",
170-
"message": "The data has been deleted with success. The app will close to finish the operation, but feel free to restart it when you'll be ready !"
170+
"message": {
171+
"appWillClose": "The data has been deleted with success. The app will close to finish the operation, but feel free to restart it when you'll be ready !",
172+
"closeAppManually": "The data has been deleted with success. Please restart the app to finish the operation."
173+
}
171174
}
172175
}
173176
}

lib/i18n/fr/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@
167167
},
168168
"doneDialog": {
169169
"title": "Données supprimées",
170-
"message": "Les données ont été supprimées avec succès. L'application va fermer pour terminer l'opération, mais n'hésitez pas à la relancer quand vous le souhaiterez !"
170+
"message": {
171+
"appWillClose": "Les données ont été supprimées avec succès. L'application va fermer pour terminer l'opération, mais n'hésitez pas à la relancer quand vous le souhaiterez !",
172+
"closeAppManually": "Les données ont été supprimées avec succès. Veuillez redémarrer l'application pour terminer l'opération."
173+
}
171174
}
172175
}
173176
}

lib/pages/settings/entries/clear_data.dart

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:developer';
12
import 'dart:io';
23

34
import 'package:cloud_firestore/cloud_firestore.dart';
@@ -88,25 +89,61 @@ class ClearDataSettingsEntryWidget extends ConsumerWidget {
8889
if (!context.mounted) {
8990
return;
9091
}
91-
await showDialog(
92-
context: context,
93-
builder: (context) => AlertDialog(
94-
title: Text(translations.settings.dangerZone.clearData.doneDialog.title),
95-
content: Text(translations.settings.dangerZone.clearData.doneDialog.message),
96-
scrollable: true,
97-
actions: [
92+
await _showCloseDialog(context);
93+
if (_canExitWithConfirmDialog) {
94+
await _closeApp();
95+
}
96+
},
97+
);
98+
99+
/// Shows the dialog that indicates the user he has to restart the app.
100+
Future<void> _showCloseDialog(BuildContext context) async {
101+
bool canExitWithConfirmDialog = _canExitWithConfirmDialog;
102+
await showDialog(
103+
context: context,
104+
barrierDismissible: false,
105+
builder: (context) => AlertDialog(
106+
title: Text(translations.settings.dangerZone.clearData.doneDialog.title),
107+
content: Text(
108+
canExitWithConfirmDialog ? translations.settings.dangerZone.clearData.doneDialog.message.appWillClose : translations.settings.dangerZone.clearData.doneDialog.message.closeAppManually,
109+
),
110+
scrollable: true,
111+
actions: canExitWithConfirmDialog
112+
? [
98113
TextButton(
99114
onPressed: () => Navigator.pop(context),
100115
child: Text(MaterialLocalizations.of(context).continueButtonLabel),
101116
),
102-
],
103-
),
104-
);
105-
if (currentPlatform.isMobile) {
106-
SystemChannels.platform.invokeMethod('SystemNavigator.pop', true);
107-
} else {
108-
exit(0);
109-
}
110-
},
111-
);
117+
]
118+
: null,
119+
),
120+
);
121+
}
122+
123+
/// Whether we can exit following the [_showCloseDialog] method.
124+
bool get _canExitWithConfirmDialog {
125+
switch (currentPlatform) {
126+
case Platform.android:
127+
case Platform.macOS:
128+
case Platform.linux:
129+
case Platform.windows:
130+
return true;
131+
default:
132+
return false;
133+
}
134+
}
135+
136+
/// Closes the app programmatically.
137+
Future<void> _closeApp() async {
138+
switch (currentPlatform) {
139+
case Platform.android:
140+
case Platform.macOS:
141+
case Platform.linux:
142+
await SystemNavigator.pop(animated: true);
143+
break;
144+
default:
145+
debugger();
146+
exit(0);
147+
}
148+
}
112149
}

0 commit comments

Comments
 (0)