From b5542d9f7daed4efdd9d774a3467870c15cd0b7a Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Mon, 13 Feb 2023 20:41:18 +0200 Subject: [PATCH 1/3] Add share files to share utils and unify the fix for ipad --- lib/src/screens/backup/backup_page.dart | 15 ++++-------- lib/utils/share_util.dart | 32 +++++++++++++++++++++---- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lib/src/screens/backup/backup_page.dart b/lib/src/screens/backup/backup_page.dart index a055066c0..f819e88e5 100644 --- a/lib/src/screens/backup/backup_page.dart +++ b/lib/src/screens/backup/backup_page.dart @@ -1,10 +1,9 @@ import 'dart:io'; import 'package:cake_wallet/palette.dart'; +import 'package:cake_wallet/utils/share_util.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; -import 'package:share_plus/share_plus.dart'; -import 'package:cross_file/cross_file.dart'; import 'package:cake_wallet/utils/show_bar.dart'; import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/generated/i18n.dart'; @@ -110,7 +109,7 @@ class BackupPage extends BasePage { if (Platform.isAndroid) { onExportAndroid(context, backup); } else { - await share(backup); + await share(backup, context); } }, actionLeftButton: () => Navigator.of(dialogContext).pop()); @@ -140,18 +139,14 @@ class BackupPage extends BasePage { }, actionLeftButton: () async { Navigator.of(dialogContext).pop(); - await share(backup); + await share(backup, context); }); }); } - Future share(BackupExportFile backup) async { - const mimeType = 'application/*'; + Future share(BackupExportFile backup, BuildContext context) async { final path = await backupViewModelBase.saveBackupFileLocally(backup); - await Share.shareXFiles([XFile( - path, - name: backup.name, - mimeType: mimeType)]); + await ShareUtil.shareFile(filePath: path, fileName: backup.name, context: context); await backupViewModelBase.removeBackupFileLocally(backup); } } diff --git a/lib/utils/share_util.dart b/lib/utils/share_util.dart index 5b33399c7..518590fdd 100644 --- a/lib/utils/share_util.dart +++ b/lib/utils/share_util.dart @@ -1,13 +1,37 @@ import 'package:flutter/material.dart'; import 'package:share_plus/share_plus.dart'; +import 'package:cross_file/cross_file.dart'; class ShareUtil { - static void share({required String text, required BuildContext context}) { - final box = context.findRenderObject() as RenderBox?; + static const _mimeType = 'application/*'; + static void share({required String text, required BuildContext context}) { Share.share( text, - sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size, + sharePositionOrigin: _sharePosition(context), ); } -} \ No newline at end of file + + static Future shareFile({ + required String filePath, + required String fileName, + required BuildContext context, + }) async { + Share.shareXFiles( + [ + XFile( + filePath, + name: fileName, + mimeType: _mimeType, + ) + ], + sharePositionOrigin: _sharePosition(context), + ); + } + + static Rect? _sharePosition(BuildContext context) { + final box = context.findRenderObject() as RenderBox?; + + return box!.localToGlobal(Offset.zero) & box.size; + } +} From 6d7ce369bf08d1b05bc59c88000b9f9daa976214 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Mon, 13 Feb 2023 23:05:08 +0200 Subject: [PATCH 2/3] Add connection timed out error to ignored errors [skip ci] --- lib/utils/exception_handler.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/utils/exception_handler.dart b/lib/utils/exception_handler.dart index 4cbebdb5d..ed9f00fcb 100644 --- a/lib/utils/exception_handler.dart +++ b/lib/utils/exception_handler.dart @@ -125,6 +125,7 @@ class ExceptionHandler { "errno = 9", // SocketException: Bad file descriptor "errno = 32", // SocketException: Write failed (OS Error: Broken pipe) "errno = 60", // SocketException: Operation timed out + "errno = 110", // SocketException: Connection timed out "errno = 54", // SocketException: Connection reset by peer "errno = 49", // SocketException: Can't assign requested address "errno = 28", // OS Error: No space left on device From 54dab5883f283ec4897f9c62d17cf37dd36795bb Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Wed, 15 Feb 2023 17:50:48 +0200 Subject: [PATCH 3/3] Check for context first before showing popup --- lib/src/screens/dashboard/dashboard_page.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/screens/dashboard/dashboard_page.dart b/lib/src/screens/dashboard/dashboard_page.dart index c21365aa4..173e8c4de 100644 --- a/lib/src/screens/dashboard/dashboard_page.dart +++ b/lib/src/screens/dashboard/dashboard_page.dart @@ -229,7 +229,8 @@ class DashboardPage extends BasePage { } await Future.delayed(Duration(seconds: 1)); - await showPopUp( + if (context.mounted) { + await showPopUp( context: context, builder: (BuildContext context) { return AlertWithOneAction( @@ -239,6 +240,7 @@ class DashboardPage extends BasePage { buttonText: S.of(context).understand, buttonAction: () => Navigator.of(context).pop()); }); + } }); var needToPresentYat = false;