Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class MethodChannelShare extends SharePlatform {
if (params.subject != null) 'subject': params.subject,
if (params.title != null) 'title': params.title,
if (params.uri != null) 'uri': params.uri.toString(),
if (params.airDrop != ShareAirDropAs.inherit)
'airDrop': params.airDrop.name,
};

if (params.sharePositionOrigin != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ class ShareParams {
/// Parameter ignored on other platforms.
final List<CupertinoActivityType>? excludedCupertinoActivities;

/// How AirDrop should deliver [uri] on iOS.
///
/// * [ShareAirDropAs.inherit] keeps the current URI share (raw `NSURL`,
/// Safari / page preview on the sheet).
/// * [ShareAirDropAs.url] wraps the URI like a text share so the host app
/// icon stays in the header, and AirDrop / Messages receive the URL.
/// * [ShareAirDropAs.text] sends the URI string as plain text (Notes).
///
/// Android has no AirDrop. [uri] + [title] already go out as EXTRA_TEXT /
/// EXTRA_TITLE (Nearby Share equivalent). This parameter is ignored there.
///
/// * Supported platforms: iOS
/// Parameter ignored on other platforms.
final ShareAirDropAs airDrop;

ShareParams({
this.text,
this.subject,
Expand All @@ -157,6 +172,7 @@ class ShareParams {
this.downloadFallbackEnabled = true,
this.mailToFallbackEnabled = true,
this.excludedCupertinoActivities,
this.airDrop = ShareAirDropAs.inherit,
});
}

Expand Down Expand Up @@ -222,6 +238,18 @@ enum ShareResultStatus {
///
/// See also:
/// [UIActivity.ActivityType](https://developer.apple.com/documentation/uikit/uiactivity/activitytype)
/// How iOS AirDrop should deliver a shared [ShareParams.uri].
enum ShareAirDropAs {
/// Keep the current URI-share behaviour (raw URL item).
inherit,

/// Deliver the URI as a URL (opens the link instead of Notes).
url,

/// Deliver the URI string as plain text.
text,
}

enum CupertinoActivityType {
postToFacebook,
postToTwitter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
// found in the LICENSE file.

export 'package:cross_file/cross_file.dart';

export 'platform_interface/share_plus_platform.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ void main() {
await sharePlatform.share(
ShareParams(
uri: Uri.parse('https://pub.dev/packages/share_plus'),
title: 'Join this circle',
airDrop: ShareAirDropAs.url,
sharePositionOrigin: const Rect.fromLTWH(1.0, 2.0, 3.0, 4.0),
excludedCupertinoActivities: [CupertinoActivityType.airDrop],
),
);
verify(
mockChannel.invokeMethod<String>('share', <String, dynamic>{
'uri': 'https://pub.dev/packages/share_plus',
'title': 'Join this circle',
'airDrop': 'url',
'originX': 1.0,
'originY': 2.0,
'originWidth': 3.0,
Expand Down Expand Up @@ -223,8 +227,7 @@ class MockMethodChannel extends Mock implements MethodChannel {
@override
Future<T?> invokeMethod<T>(String method, [dynamic arguments]) async {
return super.noSuchMethod(
Invocation.method(#invokeMethod, [method, arguments]),
)
as dynamic;
Invocation.method(#invokeMethod, [method, arguments]),
) as dynamic;
}
}
Loading