mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-29 06:18:51 +00:00
94 lines
3.0 KiB
Dart
94 lines
3.0 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 StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text(tr("Privacy settings"))),
|
|
body: _AccountPrivacyScreen(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AccountPrivacyScreen extends StatefulWidget {
|
|
@override
|
|
__AccountPrivacyScreenState createState() => __AccountPrivacyScreenState();
|
|
}
|
|
|
|
class __AccountPrivacyScreenState extends State<_AccountPrivacyScreen> {
|
|
@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),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|