Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/share_plus/share_plus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Sharing files is not supported on Linux.

## Requirements

- Flutter >=3.3.0
- Dart >=2.18.0 <4.0.0
- Flutter >=3.19.0
- Dart >=3.3.0 <4.0.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we had outdated info here

- iOS >=12.0
- MacOS >=10.14
- Android `compileSDK` 34
Expand Down
1 change: 0 additions & 1 deletion packages/share_plus/share_plus/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
/build/

# Web related
lib/generated_plugin_registrant.dart
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something edited automatically during the build


# Symbolication related
app.*.symbols
Expand Down
6 changes: 3 additions & 3 deletions packages/share_plus/share_plus/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ dependencies:
flutter:
sdk: flutter
share_plus: ^10.0.0
image_picker: ^1.0.0
file_selector: ^1.0.0
image_picker: ^1.1.2
file_selector: ^1.0.3

dev_dependencies:
flutter_driver:
Expand All @@ -15,7 +15,7 @@ dev_dependencies:
sdk: flutter
integration_test:
sdk: flutter
flutter_lints: ^3.0.1
flutter_lints: ^4.0.0

flutter:
uses-material-design: true
Expand Down
12 changes: 1 addition & 11 deletions packages/share_plus/share_plus/example/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@
<link rel="manifest" href="manifest.json">
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('flutter-first-frame', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
<script src="main.dart.js" type="application/javascript"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed to not see the following message in logs:

Warning: In index.html:39: Manual service worker registration deprecated. Use flutter.js service worker bootstrapping instead.

The change is the same as in flutter/packages#7114

<script src="flutter_bootstrap.js" async></script>
</body>
</html>
81 changes: 18 additions & 63 deletions packages/share_plus/share_plus/lib/src/share_plus_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import 'package:mime/mime.dart' show lookupMimeType;
import 'package:share_plus_platform_interface/share_plus_platform_interface.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
import 'package:url_launcher_web/url_launcher_web.dart';
import 'package:web/web.dart' as web
show DOMException, File, FilePropertyBag, Navigator, window;
import 'package:web/web.dart';

/// The web implementation of [SharePlatform].
class SharePlusWebPlugin extends SharePlatform {
Expand All @@ -21,20 +20,20 @@ class SharePlusWebPlugin extends SharePlatform {
SharePlatform.instance = SharePlusWebPlugin(UrlLauncherPlugin());
}

final web.Navigator _navigator;
final Navigator _navigator;

/// A constructor that allows tests to override the window object used by the plugin.
SharePlusWebPlugin(
this.urlLauncher, {
@visibleForTesting web.Navigator? debugNavigator,
}) : _navigator = debugNavigator ?? web.window.navigator;
@visibleForTesting Navigator? debugNavigator,
}) : _navigator = debugNavigator ?? window.navigator;

@override
Future<ShareResult> shareUri(
Uri uri, {
Rect? sharePositionOrigin,
}) async {
final data = ShareData.url(
final data = ShareData(
url: uri.toString(),
);

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

try {
await _navigator.share(data).toDart;
} on web.DOMException catch (e) {
} on DOMException catch (e) {
developer.log(
'Failed to share uri',
error: '${e.name}: ${e.message}',
Expand All @@ -76,12 +75,12 @@ class SharePlusWebPlugin extends SharePlatform {
}) async {
final ShareData data;
if (subject != null && subject.isNotEmpty) {
data = ShareData.textWithTitle(
data = ShareData(
title: subject,
text: text,
);
} else {
data = ShareData.text(
data = ShareData(
text: text,
);
}
Expand Down Expand Up @@ -130,7 +129,7 @@ class SharePlusWebPlugin extends SharePlatform {

// actions is success, but can't get the action name
return ShareResult.unavailable;
} on web.DOMException catch (e) {
} on DOMException catch (e) {
if (e.name case 'AbortError') {
return _resultDismissed;
}
Expand Down Expand Up @@ -160,7 +159,7 @@ class SharePlusWebPlugin extends SharePlatform {
}) async {
assert(
fileNameOverrides == null || files.length == fileNameOverrides.length);
final webFiles = <web.File>[];
final webFiles = <File>[];
for (var index = 0; index < files.length; index++) {
final xFile = files[index];
final filename = fileNameOverrides?.elementAt(index);
Expand All @@ -170,24 +169,24 @@ class SharePlusWebPlugin extends SharePlatform {
final ShareData data;
if (text != null && text.isNotEmpty) {
if (subject != null && subject.isNotEmpty) {
data = ShareData.filesWithTextAndTitle(
data = ShareData(
files: webFiles.toJS,
text: text,
title: subject,
);
} else {
data = ShareData.filesWithText(
data = ShareData(
files: webFiles.toJS,
text: text,
);
}
} else if (subject != null && subject.isNotEmpty) {
data = ShareData.filesWithTitle(
data = ShareData(
files: webFiles.toJS,
title: subject,
);
} else {
data = ShareData.files(
data = ShareData(
files: webFiles.toJS,
);
}
Expand All @@ -213,7 +212,7 @@ class SharePlusWebPlugin extends SharePlatform {

// actions is success, but can't get the action name
return ShareResult.unavailable;
} on web.DOMException catch (e) {
} on DOMException catch (e) {
if (e.name case 'AbortError') {
return _resultDismissed;
}
Expand All @@ -227,13 +226,12 @@ class SharePlusWebPlugin extends SharePlatform {
}
}

static Future<web.File> _fromXFile(XFile file, {String? nameOverride}) async {
static Future<File> _fromXFile(XFile file, {String? nameOverride}) async {
final bytes = await file.readAsBytes();
return web.File(
return File(
[bytes.buffer.toJS].toJS,
nameOverride ?? file.name,
web.FilePropertyBag()
..type = file.mimeType ?? _mimeTypeForPath(file, bytes),
FilePropertyBag()..type = file.mimeType ?? _mimeTypeForPath(file, bytes),
);
}

Expand All @@ -247,46 +245,3 @@ const _resultDismissed = ShareResult(
'',
ShareResultStatus.dismissed,
);

extension on web.Navigator {
/// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/canShare
external bool canShare(ShareData data);

/// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
external JSPromise share(ShareData data);
}

extension type ShareData._(JSObject _) implements JSObject {
external factory ShareData.text({
String text,
});

external factory ShareData.textWithTitle({
String text,
String title,
});

external factory ShareData.files({
JSArray<web.File> files,
});

external factory ShareData.filesWithText({
JSArray<web.File> files,
String text,
});

external factory ShareData.filesWithTitle({
JSArray<web.File> files,
String title,
});

external factory ShareData.filesWithTextAndTitle({
JSArray<web.File> files,
String text,
String title,
});

external factory ShareData.url({
String url,
});
}
14 changes: 7 additions & 7 deletions packages/share_plus/share_plus/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ flutter:
pluginClass: SharePlusWindowsPluginCApi

dependencies:
cross_file: ^0.3.3+4
cross_file: ^0.3.4+2
meta: ^1.8.0
mime: ^1.0.4
flutter:
Expand All @@ -37,12 +37,12 @@ dependencies:
sdk: flutter
share_plus_platform_interface: ^5.0.0
file: ">=6.1.4 <8.0.0"
url_launcher_web: ^2.0.16
url_launcher_windows: ^3.0.6
url_launcher_linux: ^3.0.5
url_launcher_platform_interface: ^2.1.2
ffi: ^2.0.1
web: ^0.5.0
url_launcher_web: ^2.3.2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only need to update this part of url_launcher to move to web: 1.0.0, but updated the rest as well.

url_launcher_windows: ^3.1.2
url_launcher_linux: ^3.1.1
url_launcher_platform_interface: ^2.3.2
ffi: ^2.1.2
web: ^1.0.0

# win32 is compatible across v4 and v5 for Win32 only (not COM)
win32: ">=4.0.0 <6.0.0"
Expand Down