ente/lib/ui/settings/danger_section_widget.dart

172 lines
4.5 KiB
Dart
Raw Normal View History

import 'package:expandable/expandable.dart';
2021-07-27 14:51:45 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_email_sender/flutter_email_sender.dart';
import 'package:photos/services/user_service.dart';
import 'package:photos/ui/settings/common_settings.dart';
2021-07-27 14:51:45 +00:00
import 'package:photos/ui/settings/settings_section_title.dart';
import 'package:photos/ui/settings/settings_text_item.dart';
import 'package:url_launcher/url_launcher.dart';
class DangerSectionWidget extends StatefulWidget {
DangerSectionWidget({Key key}) : super(key: key);
@override
_DangerSectionWidgetState createState() => _DangerSectionWidgetState();
}
class _DangerSectionWidgetState extends State<DangerSectionWidget> {
@override
Widget build(BuildContext context) {
return ExpandablePanel(
header: SettingsSectionTitle("Exit", color: Colors.red),
collapsed: Container(),
expanded: _getSectionOptions(context),
theme: getExpandableTheme(context),
);
}
Widget _getSectionOptions(BuildContext context) {
2021-07-27 14:51:45 +00:00
return Column(
children: [
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
_onLogoutTapped();
},
child: SettingsTextItem(text: "Logout", icon: Icons.navigate_next),
2021-07-27 14:51:45 +00:00
),
sectionOptionDivider,
2021-07-27 14:51:45 +00:00
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
_onDeleteAccountTapped();
},
child: SettingsTextItem(
2022-06-11 08:23:52 +00:00
text: "Delete account",
icon: Icons.navigate_next,
),
2021-07-27 14:51:45 +00:00
),
],
);
}
Future<void> _onDeleteAccountTapped() async {
AlertDialog alert = AlertDialog(
title: Text(
2022-05-30 10:52:46 +00:00
"Delete account",
2021-07-27 14:51:45 +00:00
style: TextStyle(
color: Colors.red,
),
),
content: RichText(
text: TextSpan(
children: [
TextSpan(
2022-05-30 10:52:46 +00:00
text: "Please send an email to ",
2021-07-27 14:51:45 +00:00
),
TextSpan(
text: "account-deletion@ente.io",
style: TextStyle(
color: Colors.orange[300],
),
),
TextSpan(
text:
2022-05-30 10:52:46 +00:00
" from your registered email address.\n\nYour request will be processed within 72 hours.",
2021-07-27 14:51:45 +00:00
),
],
style: TextStyle(
2022-03-05 20:52:00 +00:00
color: Theme.of(context).colorScheme.onSurface,
2021-07-27 14:51:45 +00:00
height: 1.5,
2021-07-27 17:15:34 +00:00
fontSize: 16,
2021-07-27 14:51:45 +00:00
),
),
),
actions: [
TextButton(
child: Text(
2022-05-30 10:52:46 +00:00
"Send email",
2021-07-27 14:51:45 +00:00
style: TextStyle(
color: Colors.red,
),
),
onPressed: () async {
Navigator.of(context, rootNavigator: true).pop('dialog');
try {
final Email email = Email(
recipients: ['account-deletion@ente.io'],
isHTML: false,
);
await FlutterEmailSender.send(email);
} catch (e) {
launch("mailto:account-deletion@ente.io");
}
},
),
TextButton(
child: Text(
2022-05-30 10:52:46 +00:00
"Ok",
2021-07-27 14:51:45 +00:00
style: TextStyle(
2022-03-05 20:52:00 +00:00
color: Theme.of(context).colorScheme.onSurface,
2021-07-27 14:51:45 +00:00
),
),
onPressed: () {
Navigator.of(context, rootNavigator: true).pop('dialog');
},
),
],
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
Future<void> _onLogoutTapped() async {
AlertDialog alert = AlertDialog(
title: Text(
2022-05-30 10:52:46 +00:00
"Logout",
2021-07-27 14:51:45 +00:00
style: TextStyle(
color: Colors.red,
),
),
2022-05-30 10:52:46 +00:00
content: Text("Are you sure you want to logout?"),
2021-07-27 14:51:45 +00:00
actions: [
TextButton(
child: Text(
2022-05-30 10:52:46 +00:00
"Yes, logout",
2021-07-27 14:51:45 +00:00
style: TextStyle(
color: Colors.red,
),
),
onPressed: () async {
Navigator.of(context, rootNavigator: true).pop('dialog');
await UserService.instance.logout(context);
},
),
TextButton(
child: Text(
2022-05-30 10:52:46 +00:00
"No",
2021-07-27 14:51:45 +00:00
style: TextStyle(
color: Theme.of(context).buttonColor,
),
),
onPressed: () {
Navigator.of(context, rootNavigator: true).pop('dialog');
},
),
],
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
}