1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-30 00:36:28 +00:00
comunicmobile/lib/ui/routes/settings/account_privacy_settings.dart

84 lines
2.8 KiB
Dart
Raw Normal View History

2020-05-01 08:56:57 +00:00
import 'package:comunic/helpers/account_helper.dart';
2020-05-01 08:52:53 +00:00
import 'package:comunic/ui/dialogs/input_user_password_dialog.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:settings_ui/settings_ui.dart';
/// Account privacy settings
///
/// @author Pierre HUBERT
2020-05-13 16:12:45 +00:00
class AccountPrivacySettings extends StatefulWidget {
2020-05-01 08:52:53 +00:00
@override
2020-05-13 16:12:45 +00:00
_AccountPrivacySettingsState createState() => _AccountPrivacySettingsState();
2020-05-01 08:52:53 +00:00
}
2020-05-13 16:12:45 +00:00
class _AccountPrivacySettingsState extends State<AccountPrivacySettings> {
2020-05-01 08:52:53 +00:00
@override
Widget build(BuildContext context) {
return SettingsList(sections: [
SettingsSection(title: tr("Privacy settings"), tiles: [
SettingsTile(
title: tr("Delete your account"),
subtitle:
tr("Permanently delete your account and all data related to it."),
onTap: _deleteAccount,
)
])
]);
}
/// Permanently delete user account
void _deleteAccount() async {
try {
// First dialog
if (!await showConfirmDialog(
context: context,
message: tr(
"Do you really want to delete your account? This operation CAN NOT be reverted!")))
return;
// Ask user password dialog
final password = await showUserPasswordDialog(context);
if (password == null) return;
// Last chance dialog
if (await showCupertinoDialog<bool>(
context: context,
builder: (c) => _LastChanceDeleteAccountDialog()) !=
true) return;
// Delete account
2020-05-01 08:56:57 +00:00
await AccountHelper.deleteAccount(password);
2020-05-01 08:52:53 +00:00
} catch (e, stack) {
print("Could not delete user account! $e\n$stack");
2020-05-01 08:56:57 +00:00
showSimpleSnack(context, tr("Could not delete your account!"));
2020-05-01 08:52:53 +00:00
}
}
}
class _LastChanceDeleteAccountDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoAlertDialog(
title: Text(tr("Delete your account")),
content: Text(tr(
"Let us ask you one last time. Do you really want to delete your account? If you decide to do so, your data will be permanently removed from our servers, so we will not be able to recover your account. If you decide to proceed, the deletion process will start immediatly and you will automatically get disconnected from your account.")),
actions: <Widget>[
CupertinoDialogAction(
isDefaultAction: true,
child: Text(tr("Cancel")),
onPressed: () => Navigator.of(context).pop(false),
),
CupertinoDialogAction(
isDestructiveAction: true,
child: Text(tr("Confirm")),
onPressed: () => Navigator.of(context).pop(true),
),
],
);
}
}