Add share files to share utils and unify the fix for ipad
OmarHatem committed
Feb 13, 2023 at 20:41 UTC
b5542d9f7daed4efdd9d774a3467870c15cd0b7a
2 files changed
+33
-14
lib/src/screens/backup/backup_page.dart
+5
-10
@@ -1,10 +1,9 @@
1
import 'dart:io';
2
import 'package:cake_wallet/palette.dart';
3
+import 'package:cake_wallet/utils/share_util.dart';
4
import 'package:flutter/material.dart';
5
import 'package:flutter/services.dart';
6
import 'package:flutter_mobx/flutter_mobx.dart';
6
-import 'package:share_plus/share_plus.dart';
7
-import 'package:cross_file/cross_file.dart';
7
import 'package:cake_wallet/utils/show_bar.dart';
8
import 'package:cake_wallet/routes.dart';
9
import 'package:cake_wallet/generated/i18n.dart';
@@ -110,7 +109,7 @@ class BackupPage extends BasePage {
109
if (Platform.isAndroid) {
110
onExportAndroid(context, backup);
111
} else {
113
- await share(backup);
112
+ await share(backup, context);
113
}
114
},
115
actionLeftButton: () => Navigator.of(dialogContext).pop());
@@ -140,18 +139,14 @@ class BackupPage extends BasePage {
139
},
140
actionLeftButton: () async {
141
Navigator.of(dialogContext).pop();
143
- await share(backup);
142
+ await share(backup, context);
143
});
144
});
145
}
146
148
- Future<void> share(BackupExportFile backup) async {
149
- const mimeType = 'application/*';
147
+ Future<void> share(BackupExportFile backup, BuildContext context) async {
148
final path = await backupViewModelBase.saveBackupFileLocally(backup);
151
- await Share.shareXFiles(<XFile>[XFile(
152
- path,
153
- name: backup.name,
154
- mimeType: mimeType)]);
149
+ await ShareUtil.shareFile(filePath: path, fileName: backup.name, context: context);
150
await backupViewModelBase.removeBackupFileLocally(backup);
151
}
152
}
lib/utils/share_util.dart
+28
-4
@@ -1,13 +1,37 @@
1
import 'package:flutter/material.dart';
2
import 'package:share_plus/share_plus.dart';
3
+import 'package:cross_file/cross_file.dart';
4
5
class ShareUtil {
5
- static void share({required String text, required BuildContext context}) {
6
- final box = context.findRenderObject() as RenderBox?;
6
+ static const _mimeType = 'application/*';
7
8
+ static void share({required String text, required BuildContext context}) {
9
Share.share(
10
text,
10
- sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
11
+ sharePositionOrigin: _sharePosition(context),
12
+ );
13
+ }
14
+
15
+ static Future<void> shareFile({
16
+ required String filePath,
17
+ required String fileName,
18
+ required BuildContext context,
19
+ }) async {
20
+ Share.shareXFiles(
21
+ <XFile>[
22
+ XFile(
23
+ filePath,
24
+ name: fileName,
25
+ mimeType: _mimeType,
26
+ )
27
+ ],
28
+ sharePositionOrigin: _sharePosition(context),
29
);
30
}
13
-}
\ No newline at end of file
31
+
32
+ static Rect? _sharePosition(BuildContext context) {
33
+ final box = context.findRenderObject() as RenderBox?;
34
+
35
+ return box!.localToGlobal(Offset.zero) & box.size;
36
+ }
37
+}