diff --git a/lib/pages/settings_views/global_settings_view/advanced_views/debug_view.dart b/lib/pages/settings_views/global_settings_view/advanced_views/debug_view.dart index 6b073ea69..29baad1c6 100644 --- a/lib/pages/settings_views/global_settings_view/advanced_views/debug_view.dart +++ b/lib/pages/settings_views/global_settings_view/advanced_views/debug_view.dart @@ -303,13 +303,17 @@ class _DebugViewState extends ConsumerState { Logging.instance .log("$e\n$s", level: LogLevel.Error); } - - final String? path = - await FilePicker.platform.getDirectoryPath( - dialogTitle: "Choose Backup location", - initialDirectory: dir.path, - lockParentWindow: true, - ); + String? path; + if (Platform.isAndroid) { + path = dir.path; + } else { + path = await FilePicker.platform + .getDirectoryPath( + dialogTitle: "Choose Backup location", + initialDirectory: dir.path, + lockParentWindow: true, + ); + } if (path != null) { final eventBus = EventBus(); @@ -328,7 +332,7 @@ class _DebugViewState extends ConsumerState { ), )); - await ref + final filename = await ref .read(debugServiceProvider) .exportToFile(path, eventBus); @@ -336,10 +340,26 @@ class _DebugViewState extends ConsumerState { if (mounted) { Navigator.pop(context); - unawaited(showFloatingFlushBar( - type: FlushBarType.info, - context: context, - message: 'Logs file saved')); + + if (Platform.isAndroid) { + unawaited( + showDialog( + context: context, + builder: (context) => StackOkDialog( + title: "Logs saved to", + message: "${path!}/$filename", + ), + ), + ); + } else { + unawaited( + showFloatingFlushBar( + type: FlushBarType.info, + context: context, + message: 'Logs file saved', + ), + ); + } } } }, diff --git a/lib/pages/settings_views/global_settings_view/stack_backup_views/create_auto_backup_view.dart b/lib/pages/settings_views/global_settings_view/stack_backup_views/create_auto_backup_view.dart index 22ace0a8e..b44a473b4 100644 --- a/lib/pages/settings_views/global_settings_view/stack_backup_views/create_auto_backup_view.dart +++ b/lib/pages/settings_views/global_settings_view/stack_backup_views/create_auto_backup_view.dart @@ -82,6 +82,17 @@ class _EnableAutoBackupViewState extends ConsumerState { passwordFocusNode = FocusNode(); passwordRepeatFocusNode = FocusNode(); + if (Platform.isAndroid) { + WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { + final dir = await stackFileSystem.prepareStorage(); + if (mounted) { + setState(() { + fileLocationController.text = dir.path; + }); + } + }); + } + super.initState(); } @@ -133,64 +144,70 @@ class _EnableAutoBackupViewState extends ConsumerState { const SizedBox( height: 10, ), - TextField( - onTap: () async { - try { - await stackFileSystem.prepareStorage(); + if (!Platform.isAndroid) + TextField( + onTap: Platform.isAndroid + ? null + : () async { + try { + await stackFileSystem.prepareStorage(); - if (mounted) { - await stackFileSystem.pickDir(context); - } + if (mounted) { + await stackFileSystem.pickDir(context); + } - if (mounted) { - setState(() { - fileLocationController.text = - stackFileSystem.dirPath ?? ""; - }); - } - } catch (e, s) { - Logging.instance.log("$e\n$s", level: LogLevel.Error); - } - }, - controller: fileLocationController, - style: STextStyles.field(context), - decoration: InputDecoration( - hintText: "Save to...", - suffixIcon: UnconstrainedBox( - child: Row( - children: [ - const SizedBox( - width: 16, - ), - SvgPicture.asset( - Assets.svg.folder, - color: Theme.of(context) - .extension()! - .textDark3, - width: 16, - height: 16, - ), - const SizedBox( - width: 12, - ), - ], + if (mounted) { + setState(() { + fileLocationController.text = + stackFileSystem.dirPath ?? ""; + }); + } + } catch (e, s) { + Logging.instance + .log("$e\n$s", level: LogLevel.Error); + } + }, + controller: fileLocationController, + style: STextStyles.field(context), + decoration: InputDecoration( + hintText: "Save to...", + hintStyle: STextStyles.fieldLabel(context), + suffixIcon: UnconstrainedBox( + child: Row( + children: [ + const SizedBox( + width: 16, + ), + SvgPicture.asset( + Assets.svg.folder, + color: Theme.of(context) + .extension()! + .textDark3, + width: 16, + height: 16, + ), + const SizedBox( + width: 12, + ), + ], + ), ), ), + key: const Key( + "createBackupSaveToFileLocationTextFieldKey"), + readOnly: true, + toolbarOptions: const ToolbarOptions( + copy: true, + cut: false, + paste: false, + selectAll: false, + ), + onChanged: (newValue) {}, ), - key: const Key( - "createBackupSaveToFileLocationTextFieldKey"), - readOnly: true, - toolbarOptions: const ToolbarOptions( - copy: true, - cut: false, - paste: false, - selectAll: false, + if (!Platform.isAndroid) + const SizedBox( + height: 10, ), - onChanged: (newValue) {}, - ), - const SizedBox( - height: 10, - ), ClipRRect( borderRadius: BorderRadius.circular( Constants.size.circularBorderRadius, @@ -593,8 +610,15 @@ class _EnableAutoBackupViewState extends ConsumerState { await showDialog( context: context, barrierDismissible: false, - builder: (_) => const StackOkDialog( - title: "Stack Auto Backup enabled!"), + builder: (_) => Platform.isAndroid + ? StackOkDialog( + title: + "Stack Auto Backup enabled and saved to:", + message: fileToSave, + ) + : const StackOkDialog( + title: + "Stack Auto Backup enabled!"), ); if (mounted) { passwordController.text = ""; diff --git a/lib/pages/settings_views/global_settings_view/stack_backup_views/create_backup_view.dart b/lib/pages/settings_views/global_settings_view/stack_backup_views/create_backup_view.dart index 964111cd3..8dfc7588c 100644 --- a/lib/pages/settings_views/global_settings_view/stack_backup_views/create_backup_view.dart +++ b/lib/pages/settings_views/global_settings_view/stack_backup_views/create_backup_view.dart @@ -64,6 +64,17 @@ class _RestoreFromFileViewState extends State { passwordFocusNode = FocusNode(); passwordRepeatFocusNode = FocusNode(); + if (Platform.isAndroid) { + WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { + final dir = await stackFileSystem.prepareStorage(); + if (mounted) { + setState(() { + fileLocationController.text = dir.path; + }); + } + }); + } + super.initState(); } @@ -113,88 +124,78 @@ class _RestoreFromFileViewState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - Consumer(builder: (context, ref, __) { - return Container( - color: Colors.transparent, - child: TextField( - onTap: () async { - try { - await stackFileSystem.prepareStorage(); - // ref - // .read( - // shouldShowLockscreenOnResumeStateProvider - // .state) - // .state = false; - if (mounted) { - await stackFileSystem.pickDir(context); - } + if (!Platform.isAndroid) + Consumer(builder: (context, ref, __) { + return Container( + color: Colors.transparent, + child: TextField( + onTap: Platform.isAndroid + ? null + : () async { + try { + await stackFileSystem.prepareStorage(); - // Future.delayed( - // const Duration(seconds: 2), - // () => ref - // .read( - // shouldShowLockscreenOnResumeStateProvider - // .state) - // .state = true, - // ); + if (mounted) { + await stackFileSystem + .pickDir(context); + } - setState(() { - fileLocationController.text = - stackFileSystem.dirPath ?? ""; - }); - } catch (e, s) { - // ref - // .read( - // shouldShowLockscreenOnResumeStateProvider - // .state) - // .state = true; - Logging.instance - .log("$e\n$s", level: LogLevel.Error); - } - }, - controller: fileLocationController, - style: STextStyles.field(context), - decoration: InputDecoration( - hintText: "Save to...", - suffixIcon: UnconstrainedBox( - child: Row( - children: [ - const SizedBox( - width: 16, - ), - SvgPicture.asset( - Assets.svg.folder, - color: Theme.of(context) - .extension()! - .textDark3, - width: 16, - height: 16, - ), - const SizedBox( - width: 12, - ), - ], + if (mounted) { + setState(() { + fileLocationController.text = + stackFileSystem.dirPath ?? ""; + }); + } + } catch (e, s) { + Logging.instance.log("$e\n$s", + level: LogLevel.Error); + } + }, + controller: fileLocationController, + style: STextStyles.field(context), + decoration: InputDecoration( + hintText: "Save to...", + hintStyle: STextStyles.fieldLabel(context), + suffixIcon: UnconstrainedBox( + child: Row( + children: [ + const SizedBox( + width: 16, + ), + SvgPicture.asset( + Assets.svg.folder, + color: Theme.of(context) + .extension()! + .textDark3, + width: 16, + height: 16, + ), + const SizedBox( + width: 12, + ), + ], + ), ), ), + key: const Key( + "createBackupSaveToFileLocationTextFieldKey"), + readOnly: true, + toolbarOptions: const ToolbarOptions( + copy: true, + cut: false, + paste: false, + selectAll: false, + ), + onChanged: (newValue) { + // ref.read(addressEntryDataProvider(widget.id)).address = newValue; + }, ), - key: const Key( - "createBackupSaveToFileLocationTextFieldKey"), - readOnly: true, - toolbarOptions: const ToolbarOptions( - copy: true, - cut: false, - paste: false, - selectAll: false, - ), - onChanged: (newValue) { - // ref.read(addressEntryDataProvider(widget.id)).address = newValue; - }, - ), - ); - }), - const SizedBox( - height: 8, - ), + ); + }), + if (!Platform.isAndroid) + const SizedBox( + height: 8, + ), ClipRRect( borderRadius: BorderRadius.circular( Constants.size.circularBorderRadius, @@ -315,8 +316,12 @@ class _RestoreFromFileViewState extends State { .extension()! .accentColorRed : passwordStrength < 1 - ? Theme.of(context).extension()!.accentColorYellow - : Theme.of(context).extension()!.accentColorGreen, + ? Theme.of(context) + .extension()! + .accentColorYellow + : Theme.of(context) + .extension()! + .accentColorGreen, backgroundColor: Theme.of(context) .extension()! .buttonBackSecondary, @@ -389,8 +394,12 @@ class _RestoreFromFileViewState extends State { const Spacer(), TextButton( style: shouldEnableCreate - ? Theme.of(context) .extension()!.getPrimaryEnabledButtonColor(context) - : Theme.of(context) .extension()!.getPrimaryDisabledButtonColor(context), + ? Theme.of(context) + .extension()! + .getPrimaryEnabledButtonColor(context) + : Theme.of(context) + .extension()! + .getPrimaryDisabledButtonColor(context), onPressed: !shouldEnableCreate ? null : () async { @@ -468,8 +477,14 @@ class _RestoreFromFileViewState extends State { await showDialog( context: context, barrierDismissible: false, - builder: (_) => const StackOkDialog( - title: "Backup creation succeeded"), + builder: (_) => Platform.isAndroid + ? StackOkDialog( + title: "Backup saved to:", + message: fileToSave, + ) + : const StackOkDialog( + title: + "Backup creation succeeded"), ); passwordController.text = ""; passwordRepeatController.text = ""; diff --git a/lib/pages/settings_views/global_settings_view/stack_backup_views/edit_auto_backup_view.dart b/lib/pages/settings_views/global_settings_view/stack_backup_views/edit_auto_backup_view.dart index fa14358ea..9368d3b77 100644 --- a/lib/pages/settings_views/global_settings_view/stack_backup_views/edit_auto_backup_view.dart +++ b/lib/pages/settings_views/global_settings_view/stack_backup_views/edit_auto_backup_view.dart @@ -84,6 +84,17 @@ class _EditAutoBackupViewState extends ConsumerState { passwordFocusNode = FocusNode(); passwordRepeatFocusNode = FocusNode(); + if (Platform.isAndroid) { + WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { + final dir = await stackFileSystem.prepareStorage(); + if (mounted) { + setState(() { + fileLocationController.text = dir.path; + }); + } + }); + } + super.initState(); } @@ -135,64 +146,70 @@ class _EditAutoBackupViewState extends ConsumerState { const SizedBox( height: 10, ), - TextField( - onTap: () async { - try { - await stackFileSystem.prepareStorage(); + if (!Platform.isAndroid) + TextField( + onTap: Platform.isAndroid + ? null + : () async { + try { + await stackFileSystem.prepareStorage(); - if (mounted) { - await stackFileSystem.pickDir(context); - } + if (mounted) { + await stackFileSystem.pickDir(context); + } - if (mounted) { - setState(() { - fileLocationController.text = - stackFileSystem.dirPath ?? ""; - }); - } - } catch (e, s) { - Logging.instance.log("$e\n$s", level: LogLevel.Error); - } - }, - controller: fileLocationController, - style: STextStyles.field(context), - decoration: InputDecoration( - hintText: "Save to...", - suffixIcon: UnconstrainedBox( - child: Row( - children: [ - const SizedBox( - width: 16, - ), - SvgPicture.asset( - Assets.svg.folder, - color: Theme.of(context) - .extension()! - .textDark3, - width: 16, - height: 16, - ), - const SizedBox( - width: 12, - ), - ], + if (mounted) { + setState(() { + fileLocationController.text = + stackFileSystem.dirPath ?? ""; + }); + } + } catch (e, s) { + Logging.instance + .log("$e\n$s", level: LogLevel.Error); + } + }, + controller: fileLocationController, + style: STextStyles.field(context), + decoration: InputDecoration( + hintText: "Save to...", + hintStyle: STextStyles.fieldLabel(context), + suffixIcon: UnconstrainedBox( + child: Row( + children: [ + const SizedBox( + width: 16, + ), + SvgPicture.asset( + Assets.svg.folder, + color: Theme.of(context) + .extension()! + .textDark3, + width: 16, + height: 16, + ), + const SizedBox( + width: 12, + ), + ], + ), ), ), + key: const Key( + "createBackupSaveToFileLocationTextFieldKey"), + readOnly: true, + toolbarOptions: const ToolbarOptions( + copy: true, + cut: false, + paste: false, + selectAll: false, + ), + onChanged: (newValue) {}, ), - key: const Key( - "createBackupSaveToFileLocationTextFieldKey"), - readOnly: true, - toolbarOptions: const ToolbarOptions( - copy: true, - cut: false, - paste: false, - selectAll: false, + if (!Platform.isAndroid) + const SizedBox( + height: 10, ), - onChanged: (newValue) {}, - ), - const SizedBox( - height: 10, - ), ClipRRect( borderRadius: BorderRadius.circular( Constants.size.circularBorderRadius, @@ -594,8 +611,14 @@ class _EditAutoBackupViewState extends ConsumerState { await showDialog( context: context, barrierDismissible: false, - builder: (_) => const StackOkDialog( - title: "Stack Auto Backup saved"), + builder: (_) => Platform.isAndroid + ? StackOkDialog( + title: + "Stack Auto Backup saved to:", + message: fileToSave, + ) + : const StackOkDialog( + title: "Stack Auto Backup saved"), ); if (mounted) { passwordController.text = ""; diff --git a/lib/pages/settings_views/global_settings_view/stack_backup_views/helpers/stack_file_system.dart b/lib/pages/settings_views/global_settings_view/stack_backup_views/helpers/stack_file_system.dart index 75f2b272f..3196938da 100644 --- a/lib/pages/settings_views/global_settings_view/stack_backup_views/helpers/stack_file_system.dart +++ b/lib/pages/settings_views/global_settings_view/stack_backup_views/helpers/stack_file_system.dart @@ -13,7 +13,7 @@ class StackFileSystem { final bool isDesktop = !(Platform.isAndroid || Platform.isIOS); - Future prepareStorage() async { + Future prepareStorage() async { rootPath = (await getApplicationDocumentsDirectory()); debugPrint(rootPath!.absolute.toString()); if (Platform.isAndroid) { @@ -47,6 +47,7 @@ class StackFileSystem { debugPrint("$e $s"); } startPath = sampleFolder; + return sampleFolder; } Future pickDir(BuildContext context) async { diff --git a/lib/pages/settings_views/global_settings_view/stack_backup_views/restore_from_file_view.dart b/lib/pages/settings_views/global_settings_view/stack_backup_views/restore_from_file_view.dart index feda62d0a..cec114023 100644 --- a/lib/pages/settings_views/global_settings_view/stack_backup_views/restore_from_file_view.dart +++ b/lib/pages/settings_views/global_settings_view/stack_backup_views/restore_from_file_view.dart @@ -99,29 +99,17 @@ class _RestoreFromFileViewState extends ConsumerState { onTap: () async { try { await stackFileSystem.prepareStorage(); - // ref - // .read(shouldShowLockscreenOnResumeStateProvider - // .state) - // .state = false; - await stackFileSystem.openFile(context); + if (mounted) { + await stackFileSystem.openFile(context); + } - // Future.delayed( - // const Duration(seconds: 2), - // () => ref - // .read( - // shouldShowLockscreenOnResumeStateProvider - // .state) - // .state = true, - // ); - - fileLocationController.text = - stackFileSystem.filePath ?? ""; - setState(() {}); + if (mounted) { + setState(() { + fileLocationController.text = + stackFileSystem.filePath ?? ""; + }); + } } catch (e, s) { - // ref - // .read(shouldShowLockscreenOnResumeStateProvider - // .state) - // .state = true; Logging.instance .log("$e\n$s", level: LogLevel.Error); } @@ -130,6 +118,7 @@ class _RestoreFromFileViewState extends ConsumerState { style: STextStyles.field(context), decoration: InputDecoration( hintText: "Choose file...", + hintStyle: STextStyles.fieldLabel(context), suffixIcon: UnconstrainedBox( child: Row( children: [ diff --git a/lib/services/debug_service.dart b/lib/services/debug_service.dart index e7347c6a3..c63e22cb2 100644 --- a/lib/services/debug_service.dart +++ b/lib/services/debug_service.dart @@ -75,7 +75,8 @@ class DebugService extends ChangeNotifier { level: LogLevel.Info); } - Future exportToFile(String directory, EventBus eventBus) async { + /// returns the filename of the saved logs file + Future exportToFile(String directory, EventBus eventBus) async { final now = DateTime.now(); final filename = "Stack_Wallet_logs_${now.year}_${now.month}_${now.day}_${now.hour}_${now.minute}_${now.second}.txt"; @@ -99,5 +100,6 @@ class DebugService extends ChangeNotifier { await sink.close(); eventBus.fire(1.0); + return filename; } }