@@ -9,8 +9,7 @@ import 'package:mime/mime.dart' show lookupMimeType;
9
9
import 'package:share_plus_platform_interface/share_plus_platform_interface.dart' ;
10
10
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart' ;
11
11
import 'package:url_launcher_web/url_launcher_web.dart' ;
12
- import 'package:web/web.dart' as web
13
- show DOMException, File, FilePropertyBag, Navigator, window;
12
+ import 'package:web/web.dart' ;
14
13
15
14
/// The web implementation of [SharePlatform] .
16
15
class SharePlusWebPlugin extends SharePlatform {
@@ -21,20 +20,20 @@ class SharePlusWebPlugin extends SharePlatform {
21
20
SharePlatform .instance = SharePlusWebPlugin (UrlLauncherPlugin ());
22
21
}
23
22
24
- final web. Navigator _navigator;
23
+ final Navigator _navigator;
25
24
26
25
/// A constructor that allows tests to override the window object used by the plugin.
27
26
SharePlusWebPlugin (
28
27
this .urlLauncher, {
29
- @visibleForTesting web. Navigator ? debugNavigator,
30
- }) : _navigator = debugNavigator ?? web. window.navigator;
28
+ @visibleForTesting Navigator ? debugNavigator,
29
+ }) : _navigator = debugNavigator ?? window.navigator;
31
30
32
31
@override
33
32
Future <ShareResult > shareUri (
34
33
Uri uri, {
35
34
Rect ? sharePositionOrigin,
36
35
}) async {
37
- final data = ShareData . url (
36
+ final data = ShareData (
38
37
url: uri.toString (),
39
38
);
40
39
@@ -56,7 +55,7 @@ class SharePlusWebPlugin extends SharePlatform {
56
55
57
56
try {
58
57
await _navigator.share (data).toDart;
59
- } on web. DOMException catch (e) {
58
+ } on DOMException catch (e) {
60
59
developer.log (
61
60
'Failed to share uri' ,
62
61
error: '${e .name }: ${e .message }' ,
@@ -76,12 +75,12 @@ class SharePlusWebPlugin extends SharePlatform {
76
75
}) async {
77
76
final ShareData data;
78
77
if (subject != null && subject.isNotEmpty) {
79
- data = ShareData . textWithTitle (
78
+ data = ShareData (
80
79
title: subject,
81
80
text: text,
82
81
);
83
82
} else {
84
- data = ShareData . text (
83
+ data = ShareData (
85
84
text: text,
86
85
);
87
86
}
@@ -130,7 +129,7 @@ class SharePlusWebPlugin extends SharePlatform {
130
129
131
130
// actions is success, but can't get the action name
132
131
return ShareResult .unavailable;
133
- } on web. DOMException catch (e) {
132
+ } on DOMException catch (e) {
134
133
if (e.name case 'AbortError' ) {
135
134
return _resultDismissed;
136
135
}
@@ -160,7 +159,7 @@ class SharePlusWebPlugin extends SharePlatform {
160
159
}) async {
161
160
assert (
162
161
fileNameOverrides == null || files.length == fileNameOverrides.length);
163
- final webFiles = < web. File > [];
162
+ final webFiles = < File > [];
164
163
for (var index = 0 ; index < files.length; index++ ) {
165
164
final xFile = files[index];
166
165
final filename = fileNameOverrides? .elementAt (index);
@@ -170,24 +169,24 @@ class SharePlusWebPlugin extends SharePlatform {
170
169
final ShareData data;
171
170
if (text != null && text.isNotEmpty) {
172
171
if (subject != null && subject.isNotEmpty) {
173
- data = ShareData . filesWithTextAndTitle (
172
+ data = ShareData (
174
173
files: webFiles.toJS,
175
174
text: text,
176
175
title: subject,
177
176
);
178
177
} else {
179
- data = ShareData . filesWithText (
178
+ data = ShareData (
180
179
files: webFiles.toJS,
181
180
text: text,
182
181
);
183
182
}
184
183
} else if (subject != null && subject.isNotEmpty) {
185
- data = ShareData . filesWithTitle (
184
+ data = ShareData (
186
185
files: webFiles.toJS,
187
186
title: subject,
188
187
);
189
188
} else {
190
- data = ShareData . files (
189
+ data = ShareData (
191
190
files: webFiles.toJS,
192
191
);
193
192
}
@@ -213,7 +212,7 @@ class SharePlusWebPlugin extends SharePlatform {
213
212
214
213
// actions is success, but can't get the action name
215
214
return ShareResult .unavailable;
216
- } on web. DOMException catch (e) {
215
+ } on DOMException catch (e) {
217
216
if (e.name case 'AbortError' ) {
218
217
return _resultDismissed;
219
218
}
@@ -227,12 +226,12 @@ class SharePlusWebPlugin extends SharePlatform {
227
226
}
228
227
}
229
228
230
- static Future <web. File > _fromXFile (XFile file, {String ? nameOverride}) async {
229
+ static Future <File > _fromXFile (XFile file, {String ? nameOverride}) async {
231
230
final bytes = await file.readAsBytes ();
232
- return web. File (
231
+ return File (
233
232
[bytes.buffer.toJS].toJS,
234
233
nameOverride ?? file.name,
235
- web. FilePropertyBag ()
234
+ FilePropertyBag ()
236
235
..type = file.mimeType ?? _mimeTypeForPath (file, bytes),
237
236
);
238
237
}
@@ -247,46 +246,3 @@ const _resultDismissed = ShareResult(
247
246
'' ,
248
247
ShareResultStatus .dismissed,
249
248
);
250
-
251
- extension on web.Navigator {
252
- /// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/canShare
253
- external bool canShare (ShareData data);
254
-
255
- /// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
256
- external JSPromise share (ShareData data);
257
- }
258
-
259
- extension type ShareData ._(JSObject _) implements JSObject {
260
- external factory ShareData .text ({
261
- String text,
262
- });
263
-
264
- external factory ShareData .textWithTitle ({
265
- String text,
266
- String title,
267
- });
268
-
269
- external factory ShareData .files ({
270
- JSArray <web.File > files,
271
- });
272
-
273
- external factory ShareData .filesWithText ({
274
- JSArray <web.File > files,
275
- String text,
276
- });
277
-
278
- external factory ShareData .filesWithTitle ({
279
- JSArray <web.File > files,
280
- String title,
281
- });
282
-
283
- external factory ShareData .filesWithTextAndTitle ({
284
- JSArray <web.File > files,
285
- String text,
286
- String title,
287
- });
288
-
289
- external factory ShareData .url ({
290
- String url,
291
- });
292
- }
0 commit comments