danger_section_widget.dart 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import 'package:expandable/expandable.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:photos/ente_theme_data.dart';
  4. import 'package:photos/services/user_service.dart';
  5. import 'package:photos/ui/account/delete_account_page.dart';
  6. import 'package:photos/ui/settings/common_settings.dart';
  7. import 'package:photos/ui/settings/settings_section_title.dart';
  8. import 'package:photos/ui/settings/settings_text_item.dart';
  9. import 'package:photos/utils/navigation_util.dart';
  10. class DangerSectionWidget extends StatefulWidget {
  11. const DangerSectionWidget({Key key}) : super(key: key);
  12. @override
  13. State<DangerSectionWidget> createState() => _DangerSectionWidgetState();
  14. }
  15. class _DangerSectionWidgetState extends State<DangerSectionWidget> {
  16. @override
  17. Widget build(BuildContext context) {
  18. return ExpandablePanel(
  19. header: const SettingsSectionTitle("Exit", color: Colors.red),
  20. collapsed: Container(),
  21. expanded: _getSectionOptions(context),
  22. theme: getExpandableTheme(context),
  23. );
  24. }
  25. Widget _getSectionOptions(BuildContext context) {
  26. return Column(
  27. children: [
  28. GestureDetector(
  29. behavior: HitTestBehavior.translucent,
  30. onTap: () {
  31. _onLogoutTapped();
  32. },
  33. child:
  34. const SettingsTextItem(text: "Logout", icon: Icons.navigate_next),
  35. ),
  36. sectionOptionDivider,
  37. GestureDetector(
  38. behavior: HitTestBehavior.translucent,
  39. onTap: () async {
  40. routeToPage(context, const DeleteAccountPage());
  41. },
  42. child: const SettingsTextItem(
  43. text: "Delete account",
  44. icon: Icons.navigate_next,
  45. ),
  46. ),
  47. ],
  48. );
  49. }
  50. Future<void> _onLogoutTapped() async {
  51. final AlertDialog alert = AlertDialog(
  52. title: const Text(
  53. "Logout",
  54. style: TextStyle(
  55. color: Colors.red,
  56. ),
  57. ),
  58. content: const Text("Are you sure you want to logout?"),
  59. actions: [
  60. TextButton(
  61. child: const Text(
  62. "Yes, logout",
  63. style: TextStyle(
  64. color: Colors.red,
  65. ),
  66. ),
  67. onPressed: () async {
  68. Navigator.of(context, rootNavigator: true).pop('dialog');
  69. await UserService.instance.logout(context);
  70. },
  71. ),
  72. TextButton(
  73. child: Text(
  74. "No",
  75. style: TextStyle(
  76. color: Theme.of(context).colorScheme.greenAlternative,
  77. ),
  78. ),
  79. onPressed: () {
  80. Navigator.of(context, rootNavigator: true).pop('dialog');
  81. },
  82. ),
  83. ],
  84. );
  85. showDialog(
  86. context: context,
  87. builder: (BuildContext context) {
  88. return alert;
  89. },
  90. );
  91. }
  92. }