You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Invoke the static `share()` method anywhere in your Dart code.
50
+
Access the `SharePlus` instance via `SharePlus.instance`.
51
+
Then, invoke the `share()` method anywhere in your Dart code.
51
52
52
53
```dart
53
-
Share.share('check out my website https://example.com');
54
+
SharePlus.instance.share(
55
+
ShareParams(text: 'check out my website https://example.com')
56
+
);
54
57
```
55
58
56
-
The `share` method also takes an optional `subject` that will be used when
57
-
sharing to email.
59
+
The `share()` method requires the `ShareParams` object,
60
+
which contains the content to share.
58
61
59
-
```dart
60
-
Share.share('check out my website https://example.com', subject: 'Look what I made!');
61
-
```
62
+
These are some of the accepted parameters of the `ShareParams` class:
63
+
64
+
-`text`: text to share.
65
+
-`title`: content or share-sheet title (if supported).
66
+
-`subject`: email subject (if supported).
67
+
68
+
Check the class documentation for more details.
62
69
63
70
`share()` returns `status` object that allows to check the result of user action in the share sheet.
64
71
65
72
```dart
66
-
final result = await Share.share('check out my website https://example.com');
73
+
final result = await SharePlus.instance.share(params);
67
74
68
75
if (result.status == ShareResultStatus.success) {
69
76
print('Thank you for sharing my website!');
@@ -72,18 +79,31 @@ if (result.status == ShareResultStatus.success) {
72
79
73
80
### Share Files
74
81
75
-
To share one or multiple files, invoke the static `shareXFiles` method anywhere in your Dart code. The method returns a `ShareResult`. Optionally, you can pass `subject`, `text` and `sharePositionOrigin`.
82
+
To share one or multiple files, provide the `files` list in `ShareParams`.
83
+
Optionally, you can pass `title`, `text` and `sharePositionOrigin`.
76
84
77
85
```dart
78
-
final result = await Share.shareXFiles([XFile('${directory.path}/image.jpg')], text: 'Great picture');
86
+
final params = ShareParams(
87
+
text: 'Great picture',
88
+
files: [XFile('${directory.path}/image.jpg')],
89
+
);
90
+
91
+
final result = await SharePlus.instance.share(params);
79
92
80
93
if (result.status == ShareResultStatus.success) {
81
94
print('Thank you for sharing the picture!');
82
95
}
83
96
```
84
97
85
98
```dart
86
-
final result = await Share.shareXFiles([XFile('${directory.path}/image1.jpg'), XFile('${directory.path}/image2.jpg')]);
99
+
final params = ShareParams(
100
+
files: [
101
+
XFile('${directory.path}/image1.jpg'),
102
+
XFile('${directory.path}/image2.jpg'),
103
+
],
104
+
);
105
+
106
+
final result = await SharePlus.instance.share(params);
87
107
88
108
if (result.status == ShareResultStatus.dismissed) {
89
109
print('Did you not like the pictures?');
@@ -96,15 +116,13 @@ See [Can I Use - Web Share API](https://caniuse.com/web-share) to understand
96
116
which browsers are supported. This builds on the [`cross_file`](https://pub.dev/packages/cross_file)
Copy file name to clipboardExpand all lines: packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/MethodCallHandler.kt
+2-26
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,8 @@
1
1
packagedev.fluttercommunity.plus.share
2
2
3
3
importandroid.os.Build
4
-
importio.flutter.BuildConfig
5
4
importio.flutter.plugin.common.MethodCall
6
5
importio.flutter.plugin.common.MethodChannel
7
-
importjava.io.IOException
8
6
9
7
/** Handles the method calls for the plugin. */
10
8
internalclassMethodCallHandler(
@@ -24,35 +22,13 @@ internal class MethodCallHandler(
0 commit comments