Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

refactor: Replace RecoveryKeyDialogLocker with RecoveryKeySheet for improved consistency and user experience

AmanRajSinghMourya8c7b0e920012
diff --git a/mobile/apps/locker/lib/ui/components/recovery_key_dialog_locker.dart b/mobile/apps/locker/lib/ui/components/recovery_key_dialog_locker.dart
deleted file mode 100644
index 559eaf0922..0000000000
--- a/mobile/apps/locker/lib/ui/components/recovery_key_dialog_locker.dart
+++ /dev/null
@@ -1,215 +0,0 @@
-import 'dart:io' as io;
-
-import 'package:bip39/bip39.dart' as bip39;
-import 'package:ente_configuration/base_configuration.dart';
-import 'package:ente_configuration/constants.dart';
-import 'package:ente_strings/ente_strings.dart';
-import "package:ente_ui/components/close_icon_button.dart";
-import "package:ente_ui/components/title_bar_title_widget.dart";
-import 'package:ente_ui/theme/ente_theme.dart';
-import 'package:ente_ui/utils/toast_util.dart';
-import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
-import 'package:locker/services/configuration.dart';
-import "package:locker/ui/components/gradient_button.dart";
-import "package:share_plus/share_plus.dart";
-
-class RecoveryKeyDialogLocker extends StatefulWidget {
- final String recoveryKey;
- final Function()? onDone;
-
- const RecoveryKeyDialogLocker({
- super.key,
- required this.recoveryKey,
- this.onDone,
- });
-
- @override
- State<RecoveryKeyDialogLocker> createState() =>
- _RecoveryKeyDialogLockerState();
-}
-
-class _RecoveryKeyDialogLockerState extends State<RecoveryKeyDialogLocker> {
- late final io.File _recoveryKeyFile;
- late final BaseConfiguration _config;
-
- @override
- void initState() {
- super.initState();
- _config = Configuration.instance;
- _recoveryKeyFile = io.File(
- "${_config.getTempDirectory()}ente-recovery-key.txt",
- );
- }
-
- @override
- void dispose() {
- // Clean up temp file if it exists
- if (_recoveryKeyFile.existsSync()) {
- _recoveryKeyFile.deleteSync();
- }
- super.dispose();
- }
-
- @override
- Widget build(BuildContext context) {
- final colorScheme = getEnteColorScheme(context);
- final textTheme = getEnteTextTheme(context);
-
- // Convert recovery key to mnemonic words
- final String recoveryKeyMnemonic =
- bip39.entropyToMnemonic(widget.recoveryKey);
-
- if (recoveryKeyMnemonic.split(' ').length != mnemonicKeyWordCount) {
- throw AssertionError(
- 'Recovery code should have $mnemonicKeyWordCount words',
- );
- }
-
- return Dialog(
- backgroundColor: colorScheme.backgroundElevated2,
- insetPadding: const EdgeInsets.symmetric(horizontal: 24, vertical: 24),
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(24),
- ),
- child: Container(
- constraints: const BoxConstraints(maxWidth: 400),
- padding: const EdgeInsets.all(24),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- TitleBarTitleWidget(
- title: context.strings.recoveryKey,
- ),
- CloseIconButton(
- onTap: () => _handleClose(),
- ),
- ],
- ),
- const SizedBox(height: 16),
- Text(
- context.strings.recoveryKeyOnForgotPassword,
- style: textTheme.body.copyWith(
- color: colorScheme.textMuted,
- ),
- ),
- const SizedBox(height: 24),
- Container(
- decoration: BoxDecoration(
- color: colorScheme.primary700,
- borderRadius: BorderRadius.circular(16),
- ),
- child: Stack(
- children: [
- Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 22,
- vertical: 24,
- ),
- child: SelectableText(
- recoveryKeyMnemonic,
- style: textTheme.body.copyWith(
- color: Colors.white,
- fontFamily: 'monospace',
- letterSpacing: 0.5,
- height: 1.5,
- ),
- textAlign: TextAlign.justify,
- ),
- ),
- Positioned(
- right: 0,
- top: 0,
- child: IconButton(
- onPressed: () => _copyToClipboard(recoveryKeyMnemonic),
- visualDensity: VisualDensity.compact,
- icon: Icon(
- Icons.copy_rounded,
- size: 20,
- color: colorScheme.primary500,
- ),
- tooltip: 'Copy to clipboard',
- ),
- ),
- ],
- ),
- ),
- const SizedBox(height: 16),
- Text(
- context.strings.recoveryKeySaveDescription,
- style: textTheme.small.copyWith(
- color: colorScheme.textMuted,
- ),
- ),
- const SizedBox(height: 24),
- SizedBox(
- width: double.infinity,
- child: GradientButton(
- onTap: () => _shareRecoveryKey(recoveryKeyMnemonic),
- text: 'Share recovery key',
- ),
- ),
- ],
- ),
- ),
- );
- }
-
- Future<void> _copyToClipboard(String recoveryKey) async {
- await Clipboard.setData(ClipboardData(text: recoveryKey));
- if (mounted) {
- showShortToast(
- context,
- context.strings.recoveryKeyCopiedToClipboard,
- );
- }
- }
-
- Future<void> _shareRecoveryKey(String recoveryKey) async {
- try {
- if (_recoveryKeyFile.existsSync()) {
- await _recoveryKeyFile.delete();
- }
- _recoveryKeyFile.writeAsStringSync(recoveryKey);
-
- await SharePlus.instance.share(
- ShareParams(
- files: [XFile(_recoveryKeyFile.path)],
- ),
- );
- } catch (e) {
- if (mounted) {
- showShortToast(context, 'Failed to share recovery key');
- }
- }
- }
-
- void _handleClose() {
- Navigator.of(context).pop();
- if (widget.onDone != null) {
- widget.onDone!();
- }
- }
-}
-
-// Helper function to show the recovery key dialog
-Future<void> showRecoveryKeyDialogLocker(
- BuildContext context, {
- required String recoveryKey,
- Function()? onDone,
-}) {
- return showDialog(
- context: context,
- barrierDismissible: false,
- builder: (BuildContext context) {
- return RecoveryKeyDialogLocker(
- recoveryKey: recoveryKey,
- onDone: onDone,
- );
- },
- );
-}
diff --git a/mobile/apps/locker/lib/ui/components/recovery_key_sheet.dart b/mobile/apps/locker/lib/ui/components/recovery_key_sheet.dart
new file mode 100644
index 0000000000..a249bb29f2
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/components/recovery_key_sheet.dart
@@ -0,0 +1,213 @@
+import 'dart:io' as io;
+
+import 'package:bip39/bip39.dart' as bip39;
+import 'package:ente_configuration/base_configuration.dart';
+import 'package:ente_configuration/constants.dart';
+import 'package:ente_strings/ente_strings.dart';
+import "package:ente_ui/components/close_icon_button.dart";
+import 'package:ente_ui/theme/ente_theme.dart';
+import 'package:ente_ui/utils/toast_util.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:locker/services/configuration.dart';
+import "package:locker/ui/components/gradient_button.dart";
+import "package:share_plus/share_plus.dart";
+
+class RecoveryKeySheet extends StatefulWidget {
+ final String recoveryKey;
+
+ const RecoveryKeySheet({
+ super.key,
+ required this.recoveryKey,
+ });
+
+ @override
+ State<RecoveryKeySheet> createState() => _RecoveryKeySheetState();
+}
+
+class _RecoveryKeySheetState extends State<RecoveryKeySheet> {
+ late final io.File _recoveryKeyFile;
+ late final BaseConfiguration _config;
+
+ @override
+ void initState() {
+ super.initState();
+ _config = Configuration.instance;
+ _recoveryKeyFile = io.File(
+ "${_config.getTempDirectory()}ente-recovery-key.txt",
+ );
+ }
+
+ @override
+ void dispose() {
+ // Clean up temp file if it exists
+ if (_recoveryKeyFile.existsSync()) {
+ _recoveryKeyFile.deleteSync();
+ }
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ // Convert recovery key to mnemonic words
+ final String recoveryKeyMnemonic =
+ bip39.entropyToMnemonic(widget.recoveryKey);
+
+ if (recoveryKeyMnemonic.split(' ').length != mnemonicKeyWordCount) {
+ throw AssertionError(
+ 'Recovery code should have $mnemonicKeyWordCount words',
+ );
+ }
+
+ return Container(
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated2,
+ borderRadius: const BorderRadius.only(
+ topLeft: Radius.circular(24),
+ topRight: Radius.circular(24),
+ ),
+ ),
+ child: SafeArea(
+ top: false,
+ child: Padding(
+ padding: const EdgeInsets.all(16),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ context.strings.recoveryKey,
+ style: textTheme.largeBold,
+ ),
+ CloseIconButton(
+ onTap: () => _handleClose(),
+ ),
+ ],
+ ),
+ const SizedBox(height: 16),
+ Text(
+ context.strings.recoveryKeyOnForgotPassword,
+ style: textTheme.body.copyWith(
+ color: colorScheme.textMuted,
+ ),
+ ),
+ const SizedBox(height: 24),
+ Container(
+ decoration: BoxDecoration(
+ color: colorScheme.primary700,
+ borderRadius: BorderRadius.circular(16),
+ ),
+ child: Stack(
+ children: [
+ Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 22,
+ vertical: 24,
+ ),
+ child: SelectableText(
+ recoveryKeyMnemonic,
+ style: textTheme.body.copyWith(
+ color: Colors.white,
+ fontFamily: 'monospace',
+ letterSpacing: 0.5,
+ height: 1.5,
+ ),
+ textAlign: TextAlign.justify,
+ ),
+ ),
+ Positioned(
+ right: 0,
+ top: 0,
+ child: IconButton(
+ onPressed: () => _copyToClipboard(recoveryKeyMnemonic),
+ visualDensity: VisualDensity.compact,
+ icon: Icon(
+ Icons.copy_rounded,
+ size: 20,
+ color: colorScheme.primary500,
+ ),
+ tooltip: 'Copy to clipboard',
+ ),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(height: 16),
+ Text(
+ context.strings.recoveryKeySaveDescription,
+ style: textTheme.small.copyWith(
+ color: colorScheme.textMuted,
+ ),
+ ),
+ const SizedBox(height: 24),
+ SizedBox(
+ width: double.infinity,
+ child: GradientButton(
+ onTap: () => _shareRecoveryKey(recoveryKeyMnemonic),
+ text: 'Share recovery key',
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+
+ Future<void> _copyToClipboard(String recoveryKey) async {
+ await Clipboard.setData(ClipboardData(text: recoveryKey));
+ if (mounted) {
+ showShortToast(
+ context,
+ context.strings.recoveryKeyCopiedToClipboard,
+ );
+ }
+ }
+
+ Future<void> _shareRecoveryKey(String recoveryKey) async {
+ try {
+ if (_recoveryKeyFile.existsSync()) {
+ await _recoveryKeyFile.delete();
+ }
+ _recoveryKeyFile.writeAsStringSync(recoveryKey);
+
+ await SharePlus.instance.share(
+ ShareParams(
+ files: [XFile(_recoveryKeyFile.path)],
+ ),
+ );
+ } catch (e) {
+ if (mounted) {
+ showShortToast(context, 'Failed to share recovery key');
+ }
+ }
+ }
+
+ void _handleClose() {
+ Navigator.of(context).pop();
+ }
+}
+
+Future<void> showRecoveryKeySheet(
+ BuildContext context, {
+ required String recoveryKey,
+}) {
+ return showModalBottomSheet<void>(
+ context: context,
+ isScrollControlled: true,
+ isDismissible: false,
+ enableDrag: false,
+ backgroundColor: Colors.transparent,
+ builder: (BuildContext context) {
+ return RecoveryKeySheet(
+ recoveryKey: recoveryKey,
+ );
+ },
+ );
+}
diff --git a/mobile/apps/locker/lib/ui/drawer/account_section_widget.dart b/mobile/apps/locker/lib/ui/drawer/account_section_widget.dart
index 15c57cc0bc..207655fc81 100644
--- a/mobile/apps/locker/lib/ui/drawer/account_section_widget.dart
+++ b/mobile/apps/locker/lib/ui/drawer/account_section_widget.dart
@@ -11,7 +11,7 @@ import "package:locker/l10n/l10n.dart";
import "package:locker/services/configuration.dart";
import "package:locker/ui/components/change_email_dialog_locker.dart";
import "package:locker/ui/components/expandable_menu_item_widget.dart";
-import "package:locker/ui/components/recovery_key_dialog_locker.dart";
+import "package:locker/ui/components/recovery_key_sheet.dart";
class AccountSectionWidget extends StatelessWidget {
const AccountSectionWidget({super.key});
@@ -76,10 +76,9 @@ class AccountSectionWidget extends StatelessWidget {
);
return;
}
- await showRecoveryKeyDialogLocker(
+ await showRecoveryKeySheet(
context,
recoveryKey: recoveryKey,
- onDone: () {},
);
}
},