account_section_widget.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // @dart=2.9
  2. import 'package:ente_auth/core/configuration.dart';
  3. import 'package:ente_auth/services/local_authentication_service.dart';
  4. import 'package:ente_auth/theme/ente_theme.dart';
  5. import 'package:ente_auth/ui/account/change_email_dialog.dart';
  6. import 'package:ente_auth/ui/account/password_entry_page.dart';
  7. import 'package:ente_auth/ui/account/recovery_key_page.dart';
  8. import 'package:ente_auth/ui/components/captioned_text_widget.dart';
  9. import 'package:ente_auth/ui/components/expandable_menu_item_widget.dart';
  10. import 'package:ente_auth/ui/components/menu_item_widget.dart';
  11. import 'package:ente_auth/ui/settings/common_settings.dart';
  12. import 'package:ente_auth/utils/dialog_util.dart';
  13. import 'package:ente_auth/utils/navigation_util.dart';
  14. import 'package:flutter/material.dart';
  15. import 'package:flutter_sodium/flutter_sodium.dart';
  16. class AccountSectionWidget extends StatelessWidget {
  17. AccountSectionWidget({Key key}) : super(key: key);
  18. @override
  19. Widget build(BuildContext context) {
  20. return ExpandableMenuItemWidget(
  21. title: "Account",
  22. selectionOptionsWidget: _getSectionOptions(context),
  23. leadingIcon: Icons.account_circle_outlined,
  24. );
  25. }
  26. Column _getSectionOptions(BuildContext context) {
  27. List<Widget> children = [];
  28. children.addAll([
  29. sectionOptionSpacing,
  30. MenuItemWidget(
  31. captionedTextWidget: const CaptionedTextWidget(
  32. title: "Recovery key",
  33. ),
  34. pressedColor: getEnteColorScheme(context).fillFaint,
  35. trailingIcon: Icons.chevron_right_outlined,
  36. trailingIconIsMuted: true,
  37. onTap: () async {
  38. final hasAuthenticated = await LocalAuthenticationService.instance
  39. .requestLocalAuthentication(
  40. context,
  41. "Please authenticate to view your recovery key",
  42. );
  43. if (hasAuthenticated) {
  44. String recoveryKey;
  45. try {
  46. recoveryKey =
  47. Sodium.bin2hex(Configuration.instance.getRecoveryKey());
  48. } catch (e) {
  49. showGenericErrorDialog(context);
  50. return;
  51. }
  52. routeToPage(
  53. context,
  54. RecoveryKeyPage(
  55. recoveryKey,
  56. "OK",
  57. showAppBar: true,
  58. onDone: () {},
  59. ),
  60. );
  61. }
  62. },
  63. ),
  64. sectionOptionSpacing,
  65. MenuItemWidget(
  66. captionedTextWidget: const CaptionedTextWidget(
  67. title: "Change email",
  68. ),
  69. pressedColor: getEnteColorScheme(context).fillFaint,
  70. trailingIcon: Icons.chevron_right_outlined,
  71. trailingIconIsMuted: true,
  72. onTap: () async {
  73. final hasAuthenticated = await LocalAuthenticationService.instance
  74. .requestLocalAuthentication(
  75. context,
  76. "Please authenticate to change your email",
  77. );
  78. if (hasAuthenticated) {
  79. showDialog(
  80. context: context,
  81. builder: (BuildContext context) {
  82. return const ChangeEmailDialog();
  83. },
  84. barrierColor: Colors.black.withOpacity(0.85),
  85. barrierDismissible: false,
  86. );
  87. }
  88. },
  89. ),
  90. sectionOptionSpacing,
  91. MenuItemWidget(
  92. captionedTextWidget: const CaptionedTextWidget(
  93. title: "Change password",
  94. ),
  95. pressedColor: getEnteColorScheme(context).fillFaint,
  96. trailingIcon: Icons.chevron_right_outlined,
  97. trailingIconIsMuted: true,
  98. onTap: () async {
  99. final hasAuthenticated = await LocalAuthenticationService.instance
  100. .requestLocalAuthentication(
  101. context,
  102. "Please authenticate to change your password",
  103. );
  104. if (hasAuthenticated) {
  105. Navigator.of(context).push(
  106. MaterialPageRoute(
  107. builder: (BuildContext context) {
  108. return const PasswordEntryPage(
  109. mode: PasswordEntryMode.update,
  110. );
  111. },
  112. ),
  113. );
  114. }
  115. },
  116. ),
  117. sectionOptionSpacing,
  118. ]);
  119. return Column(
  120. children: children,
  121. );
  122. }
  123. }