-
-
Notifications
You must be signed in to change notification settings - Fork 973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(share_plus): remove canLaunch
check
#1315
Changes from 4 commits
26ed90f
90b6cfb
bfa14da
de129d1
8d3c207
c4427dd
88ab02c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ class SharePlusLinuxPlugin extends SharePlatform { | |
} | ||
|
||
/// Share text. | ||
/// Throws a [PlatformException] if `mailto:` scheme cannot be handled. | ||
@override | ||
Future<void> share( | ||
String text, { | ||
|
@@ -40,10 +39,12 @@ class SharePlusLinuxPlugin extends SharePlatform { | |
.join('&'), | ||
); | ||
|
||
if (await urlLauncher.canLaunch(uri.toString())) { | ||
await urlLauncher.launchUrl(uri.toString(), const LaunchOptions()); | ||
} else { | ||
throw Exception('Unable to share on web'); | ||
final launchResult = await urlLauncher.launchUrl( | ||
uri.toString(), | ||
const LaunchOptions(), | ||
); | ||
if (!launchResult) { | ||
throw Exception('Failed to launch mailto: URI'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As commented, the launchUrl can either return false or fail with an exception, in the case of returning false we throw an Exception. I did not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it makes sense. |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:url_launcher_platform_interface/link.dart'; | ||
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; | ||
|
||
class MockUrlLauncherPlatform extends UrlLauncherPlatform { | ||
String? url; | ||
bool canLaunchMockValue = true; | ||
|
||
@override | ||
LinkDelegate? get linkDelegate => throw UnimplementedError(); | ||
|
||
@override | ||
Future<bool> canLaunch(String url) async { | ||
return canLaunchMockValue; | ||
} | ||
|
||
@override | ||
Future<bool> launch( | ||
String url, { | ||
required bool useSafariVC, | ||
required bool useWebView, | ||
required bool enableJavaScript, | ||
required bool enableDomStorage, | ||
required bool universalLinksOnly, | ||
required Map<String, String> headers, | ||
String? webOnlyWindowName, | ||
}) async { | ||
this.url = url; | ||
return canLaunchMockValue; | ||
miquelbeltran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed for consistency with the other platforms