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
8 changes: 4 additions & 4 deletions packages/share_plus/share_plus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ Sharing files is not supported on Linux.

## Requirements

- Flutter >=3.22.0
- Dart >=3.4.0 <4.0.0
- iOS >=12.0
- macOS >=10.14
- Flutter >=3.41.0
- Dart >=3.11.0 <4.0.0
- iOS >=13.0
- macOS >=10.15
- Java 17
- Kotlin 2.2.0
- Android Gradle Plugin >=8.12.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>13.0</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import UIKit
import Flutter
import UIKit

@main
@objc class AppDelegate: FlutterAppDelegate {
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
}
}
25 changes: 23 additions & 2 deletions packages/share_plus/share_plus/example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSPhotoLibraryUsageDescription</key>
<string>Load photos for sharing functionality</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneClassName</key>
<string>UIWindowScene</string>
<key>UISceneConfigurationName</key>
<string>flutter</string>
<key>UISceneDelegateClassName</key>
<string>FlutterSceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand All @@ -45,8 +68,6 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSPhotoLibraryUsageDescription</key>
<string>Load photos for sharing functionality</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
Expand Down
5 changes: 3 additions & 2 deletions packages/share_plus/share_plus/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ class MyHomePageState extends State<MyHomePage> {
},
icon: const Icon(Icons.add),
),
if (Platform.isIOS || Platform.isMacOS) const SizedBox(height: 16),
if (Platform.isIOS || Platform.isMacOS)
if (!kIsWeb && (Platform.isIOS || Platform.isMacOS))
const SizedBox(height: 16),
if (!kIsWeb && (Platform.isIOS || Platform.isMacOS))
ElevatedButton(
onPressed: _onSelectExcludedActivityType,
child: const Text('Add Excluded Activity Type'),
Expand Down
6 changes: 4 additions & 2 deletions packages/share_plus/share_plus/lib/src/share_plus_linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ class SharePlusLinuxPlugin extends SharePlatform {
final uri = Uri(
scheme: 'mailto',
query: queryParameters.entries
.map((e) =>
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value ?? '')}')
.map(
(e) =>
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value ?? '')}',
)
.join('&'),
);

Expand Down
59 changes: 15 additions & 44 deletions packages/share_plus/share_plus/lib/src/share_plus_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ class SharePlusWebPlugin extends SharePlatform {
try {
canShare = _navigator.canShare(data);
} on NoSuchMethodError catch (e) {
developer.log(
'Share API is not supported in this User Agent.',
error: e,
);
developer.log('Share API is not supported in this User Agent.', error: e);

return _fallback(params, 'Navigator.canShare() is unavailable');
}
Expand All @@ -56,10 +53,7 @@ class SharePlusWebPlugin extends SharePlatform {
return _resultDismissed;
}

developer.log(
'Failed to share uri',
error: '${e.name}: ${e.message}',
);
developer.log('Failed to share uri', error: '${e.name}: ${e.message}');

return _fallback(params, 'Navigator.share() failed: ${e.message}');
}
Expand Down Expand Up @@ -98,38 +92,19 @@ class SharePlusWebPlugin extends SharePlatform {
}

if (uri != null) {
data = ShareData(
url: uri,
);
data = ShareData(url: uri);
} else if (webFiles.isNotEmpty && text != null && title != null) {
data = ShareData(
text: text,
title: title,
files: webFiles.toJS,
);
data = ShareData(text: text, title: title, files: webFiles.toJS);
} else if (webFiles.isNotEmpty && text != null) {
data = ShareData(
text: text,
files: webFiles.toJS,
);
data = ShareData(text: text, files: webFiles.toJS);
} else if (webFiles.isNotEmpty && title != null) {
data = ShareData(
title: title,
files: webFiles.toJS,
);
data = ShareData(title: title, files: webFiles.toJS);
} else if (webFiles.isNotEmpty) {
data = ShareData(
files: webFiles.toJS,
);
data = ShareData(files: webFiles.toJS);
} else if (text != null && title != null) {
data = ShareData(
text: text,
title: title,
);
data = ShareData(text: text, title: title);
} else {
data = ShareData(
text: text!,
);
data = ShareData(text: text!);
}

return data;
Expand Down Expand Up @@ -161,17 +136,16 @@ class SharePlusWebPlugin extends SharePlatform {
throw Exception(error);
}

final queryParameters = {
if (subject != null) 'subject': subject,
'body': text,
};
final queryParameters = {'subject': ?subject, 'body': text};

// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
final uri = Uri(
scheme: 'mailto',
query: queryParameters.entries
.map((e) =>
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
.map(
(e) =>
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}',
)
.join('&'),
);

Expand Down Expand Up @@ -227,7 +201,4 @@ class SharePlusWebPlugin extends SharePlatform {
}
}

const _resultDismissed = ShareResult(
'',
ShareResultStatus.dismissed,
);
const _resultDismissed = ShareResult('', ShareResultStatus.dismissed);
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ class SharePlusWindowsPlugin extends SharePlatform {
final uri = Uri(
scheme: 'mailto',
query: queryParameters.entries
.map((e) =>
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value ?? '')}')
.map(
(e) =>
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value ?? '')}',
)
.join('&'),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ class VersionHelper {
..wServicePackMajor = 0
..wServicePackMinor = 0
..wSuiteMask = 0
..wProductType = 0
..wReserved = 0;
final rtlGetVersion = DynamicLibrary.open('ntdll.dll').lookupFunction<
Void Function(Pointer<OSVERSIONINFOEX>),
void Function(Pointer<OSVERSIONINFOEX>)>('RtlGetVersion');
..wProductType = 0;
final rtlGetVersion = DynamicLibrary.open('ntdll.dll')
.lookupFunction<
Void Function(Pointer<OSVERSIONINFOEX>),
void Function(Pointer<OSVERSIONINFOEX>)
>('RtlGetVersion');
rtlGetVersion(pointer);
isWindows10RS5OrGreater =
pointer.ref.dwBuildNumber >= kWindows10RS5BuildNumber;
Expand Down
26 changes: 13 additions & 13 deletions packages/share_plus/share_plus/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ flutter:
pluginClass: SharePlusWindowsPluginCApi

dependencies:
cross_file: ^0.3.4+2
meta: ^1.8.0
mime: ">=1.0.4 <3.0.0"
cross_file: ^0.3.5+2
meta: ^1.17.0
mime: ^2.0.0
flutter:
sdk: flutter
flutter_web_plugins:
sdk: flutter
share_plus_platform_interface: ^6.1.0
file: ">=6.1.4 <8.0.0"
url_launcher_web: ^2.3.2
url_launcher_windows: ^3.1.2
url_launcher_linux: ^3.1.1
file: ^7.0.1
url_launcher_web: ^2.4.2
url_launcher_windows: ^3.1.5
url_launcher_linux: ^3.2.2
url_launcher_platform_interface: ^2.3.2
ffi: ^2.1.2
web: ^1.0.0
win32: ^5.5.3
ffi: ^2.2.0
web: ^1.1.1
win32: ^6.0.0

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ">=4.0.0 <6.0.0"
flutter_lints: ^6.0.0

environment:
sdk: ">=3.4.0 <4.0.0"
flutter: ">=3.22.0"
sdk: ">=3.11.0 <4.0.0"
flutter: ">=3.41.0"

18 changes: 9 additions & 9 deletions packages/share_plus/share_plus/test/share_plus_linux_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ void main() {
test('url encoding is correct for &', () async {
final mock = MockUrlLauncherPlatform();

await SharePlusLinuxPlugin(mock).share(
ShareParams(text: 'foo&bar', subject: 'bar&foo'),
);
await SharePlusLinuxPlugin(
mock,
).share(ShareParams(text: 'foo&bar', subject: 'bar&foo'));

expect(mock.url, 'mailto:?subject=bar%26foo&body=foo%26bar');
});
Expand All @@ -24,19 +24,19 @@ void main() {
test('url encoding is correct for spaces', () async {
final mock = MockUrlLauncherPlatform();

await SharePlusLinuxPlugin(mock).share(
ShareParams(text: 'foo bar', subject: 'bar foo'),
);
await SharePlusLinuxPlugin(
mock,
).share(ShareParams(text: 'foo bar', subject: 'bar foo'));

expect(mock.url, 'mailto:?subject=bar%20foo&body=foo%20bar');
});

test('can share URI on Linux', () async {
final mock = MockUrlLauncherPlatform();

await SharePlusLinuxPlugin(mock).share(
ShareParams(uri: Uri.parse('http://example.com')),
);
await SharePlusLinuxPlugin(
mock,
).share(ShareParams(uri: Uri.parse('http://example.com')));

expect(mock.url, 'mailto:?body=http%3A%2F%2Fexample.com');
});
Expand Down
42 changes: 23 additions & 19 deletions packages/share_plus/share_plus/test/share_plus_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ void main() {
);
});

test('share throws ArgumentError if both uri and text are provided',
() async {
expect(
() => sharePlus.share(
ShareParams(
uri: Uri.parse('https://example.com'),
text: 'text',
test(
'share throws ArgumentError if both uri and text are provided',
() async {
expect(
() => sharePlus.share(
ShareParams(uri: Uri.parse('https://example.com'), text: 'text'),
),
),
throwsA(isA<ArgumentError>()),
);
});
throwsA(isA<ArgumentError>()),
);
},
);

test('share throws ArgumentError if text is empty', () async {
expect(
Expand All @@ -47,14 +46,19 @@ void main() {
});

test(
'share throws ArgumentError if fileNameOverrides length does not match files length',
() async {
expect(
() => sharePlus.share(ShareParams(
files: [XFile('path')], fileNameOverrides: ['name1', 'name2'])),
throwsA(isA<ArgumentError>()),
);
});
'share throws ArgumentError if fileNameOverrides length does not match files length',
() async {
expect(
() => sharePlus.share(
ShareParams(
files: [XFile('path')],
fileNameOverrides: ['name1', 'name2'],
),
),
throwsA(isA<ArgumentError>()),
);
},
);

test('share calls platform share method with correct params', () async {
final params = ShareParams(text: 'text');
Expand Down
Loading
Loading