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

84 lines
2.8 KiB
Dart

import 'package:comunic/helpers/account_helper.dart';
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
class AccountPrivacySettings extends StatefulWidget {
@override
_AccountPrivacySettingsState createState() => _AccountPrivacySettingsState();
}
class _AccountPrivacySettingsState extends State<AccountPrivacySettings> {
@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
await AccountHelper.deleteAccount(password);
} catch (e, stack) {
print("Could not delete user account! $e\n$stack");
showSimpleSnack(context, tr("Could not delete your account!"));
}
}
}
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),
),
],
);
}
}