Skip to content

Commit 4a86dc6

Browse files
committed
chore(share_plus): Update web package to 1.0.0
1 parent 4cc53af commit 4a86dc6

File tree

1 file changed

+18
-62
lines changed

1 file changed

+18
-62
lines changed

packages/share_plus/share_plus/lib/src/share_plus_web.dart

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import 'package:mime/mime.dart' show lookupMimeType;
99
import 'package:share_plus_platform_interface/share_plus_platform_interface.dart';
1010
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
1111
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';
1413

1514
/// The web implementation of [SharePlatform].
1615
class SharePlusWebPlugin extends SharePlatform {
@@ -21,20 +20,20 @@ class SharePlusWebPlugin extends SharePlatform {
2120
SharePlatform.instance = SharePlusWebPlugin(UrlLauncherPlugin());
2221
}
2322

24-
final web.Navigator _navigator;
23+
final Navigator _navigator;
2524

2625
/// A constructor that allows tests to override the window object used by the plugin.
2726
SharePlusWebPlugin(
2827
this.urlLauncher, {
29-
@visibleForTesting web.Navigator? debugNavigator,
30-
}) : _navigator = debugNavigator ?? web.window.navigator;
28+
@visibleForTesting Navigator? debugNavigator,
29+
}) : _navigator = debugNavigator ?? window.navigator;
3130

3231
@override
3332
Future<ShareResult> shareUri(
3433
Uri uri, {
3534
Rect? sharePositionOrigin,
3635
}) async {
37-
final data = ShareData.url(
36+
final data = ShareData(
3837
url: uri.toString(),
3938
);
4039

@@ -56,7 +55,7 @@ class SharePlusWebPlugin extends SharePlatform {
5655

5756
try {
5857
await _navigator.share(data).toDart;
59-
} on web.DOMException catch (e) {
58+
} on DOMException catch (e) {
6059
developer.log(
6160
'Failed to share uri',
6261
error: '${e.name}: ${e.message}',
@@ -76,12 +75,12 @@ class SharePlusWebPlugin extends SharePlatform {
7675
}) async {
7776
final ShareData data;
7877
if (subject != null && subject.isNotEmpty) {
79-
data = ShareData.textWithTitle(
78+
data = ShareData(
8079
title: subject,
8180
text: text,
8281
);
8382
} else {
84-
data = ShareData.text(
83+
data = ShareData(
8584
text: text,
8685
);
8786
}
@@ -130,7 +129,7 @@ class SharePlusWebPlugin extends SharePlatform {
130129

131130
// actions is success, but can't get the action name
132131
return ShareResult.unavailable;
133-
} on web.DOMException catch (e) {
132+
} on DOMException catch (e) {
134133
if (e.name case 'AbortError') {
135134
return _resultDismissed;
136135
}
@@ -160,7 +159,7 @@ class SharePlusWebPlugin extends SharePlatform {
160159
}) async {
161160
assert(
162161
fileNameOverrides == null || files.length == fileNameOverrides.length);
163-
final webFiles = <web.File>[];
162+
final webFiles = <File>[];
164163
for (var index = 0; index < files.length; index++) {
165164
final xFile = files[index];
166165
final filename = fileNameOverrides?.elementAt(index);
@@ -170,24 +169,24 @@ class SharePlusWebPlugin extends SharePlatform {
170169
final ShareData data;
171170
if (text != null && text.isNotEmpty) {
172171
if (subject != null && subject.isNotEmpty) {
173-
data = ShareData.filesWithTextAndTitle(
172+
data = ShareData(
174173
files: webFiles.toJS,
175174
text: text,
176175
title: subject,
177176
);
178177
} else {
179-
data = ShareData.filesWithText(
178+
data = ShareData(
180179
files: webFiles.toJS,
181180
text: text,
182181
);
183182
}
184183
} else if (subject != null && subject.isNotEmpty) {
185-
data = ShareData.filesWithTitle(
184+
data = ShareData(
186185
files: webFiles.toJS,
187186
title: subject,
188187
);
189188
} else {
190-
data = ShareData.files(
189+
data = ShareData(
191190
files: webFiles.toJS,
192191
);
193192
}
@@ -213,7 +212,7 @@ class SharePlusWebPlugin extends SharePlatform {
213212

214213
// actions is success, but can't get the action name
215214
return ShareResult.unavailable;
216-
} on web.DOMException catch (e) {
215+
} on DOMException catch (e) {
217216
if (e.name case 'AbortError') {
218217
return _resultDismissed;
219218
}
@@ -227,12 +226,12 @@ class SharePlusWebPlugin extends SharePlatform {
227226
}
228227
}
229228

230-
static Future<web.File> _fromXFile(XFile file, {String? nameOverride}) async {
229+
static Future<File> _fromXFile(XFile file, {String? nameOverride}) async {
231230
final bytes = await file.readAsBytes();
232-
return web.File(
231+
return File(
233232
[bytes.buffer.toJS].toJS,
234233
nameOverride ?? file.name,
235-
web.FilePropertyBag()
234+
FilePropertyBag()
236235
..type = file.mimeType ?? _mimeTypeForPath(file, bytes),
237236
);
238237
}
@@ -247,46 +246,3 @@ const _resultDismissed = ShareResult(
247246
'',
248247
ShareResultStatus.dismissed,
249248
);
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

Comments
 (0)