From e204c62ba9da35b6b30fd11041353bc1ca7fe07c Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 1 May 2020 10:52:53 +0200 Subject: [PATCH] Ready to implement account deletion --- .../account_privacy_settings.dart | 91 +++++++++++++++++++ .../account_settings_route.dart | 9 ++ 2 files changed, 100 insertions(+) create mode 100644 lib/ui/routes/account_settings/account_privacy_settings.dart diff --git a/lib/ui/routes/account_settings/account_privacy_settings.dart b/lib/ui/routes/account_settings/account_privacy_settings.dart new file mode 100644 index 0000000..3ba1cac --- /dev/null +++ b/lib/ui/routes/account_settings/account_privacy_settings.dart @@ -0,0 +1,91 @@ +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( + context: context, + builder: (c) => _LastChanceDeleteAccountDialog()) != + true) return; + + // Delete account + print("Delete account"); + } catch (e, stack) { + print("Could not delete user account! $e\n$stack"); + } + } +} + +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: [ + 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), + ), + ], + ); + } +} diff --git a/lib/ui/routes/account_settings/account_settings_route.dart b/lib/ui/routes/account_settings/account_settings_route.dart index 0512efb..93010db 100644 --- a/lib/ui/routes/account_settings/account_settings_route.dart +++ b/lib/ui/routes/account_settings/account_settings_route.dart @@ -1,4 +1,5 @@ import 'package:comunic/ui/routes/account_settings/account_image_settings.dart'; +import 'package:comunic/ui/routes/account_settings/account_privacy_settings.dart'; import 'package:comunic/ui/routes/account_settings/account_security_settings.dart'; import 'package:comunic/ui/routes/account_settings/custom_emojies_account_settings.dart'; import 'package:comunic/ui/routes/account_settings/general_account_settings.dart'; @@ -66,6 +67,14 @@ class __AccountSettingsBodyState extends State<_AccountSettingsBody> { leading: Icon(Icons.lock), onTap: () => _openSection(AccountSecuritySettingsScreen()), ), + + // Privacy settings + SettingsTile( + title: tr("Privacy"), + subtitle: tr("Here you can make actions to protect your privacy"), + leading: Icon(Icons.security), + onTap: () => _openSection(AccountPrivacySettings()), + ), ], ) ],