You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.2 KiB
86 lines
2.2 KiB
import 'package:android_intent_plus/android_intent.dart';
|
|
import 'package:platform/platform.dart';
|
|
import 'package:sonnat/core/utils/utilities.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
class UrlLauncher {
|
|
Future<void> launchInBrowser(String url) async {
|
|
try {
|
|
await launchUrl(
|
|
Uri.parse(url),
|
|
mode: LaunchMode.externalApplication,
|
|
);
|
|
} on Exception catch (_) {
|
|
if (Utilities.isAndroid) {
|
|
AndroidIntent intent = AndroidIntent(action: 'action_view', package: 'com.habibapp.habib', data: url);
|
|
await intent.launch();
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> launchInWebViewOrVC(String url) async {
|
|
if (await canLaunchUrl(Uri.parse(url))) {
|
|
await launch(
|
|
url,
|
|
forceSafariVC: true,
|
|
forceWebView: true,
|
|
headers: <String, String>{'my_header_key': 'my_header_value'},
|
|
);
|
|
} else {
|
|
throw 'Could not launch $url';
|
|
}
|
|
}
|
|
|
|
Future<void> launchInWebViewWithJavaScript(String url) async {
|
|
if (await canLaunchUrl(Uri.parse(url))) {
|
|
await launch(
|
|
url,
|
|
forceSafariVC: true,
|
|
forceWebView: true,
|
|
enableJavaScript: true,
|
|
);
|
|
} else {
|
|
throw 'Could not launch $url';
|
|
}
|
|
}
|
|
|
|
Future<void> launchInWebViewWithDomStorage(String url) async {
|
|
if (await canLaunchUrl(Uri.parse(url))) {
|
|
await launch(
|
|
url,
|
|
forceSafariVC: true,
|
|
forceWebView: true,
|
|
enableDomStorage: true,
|
|
);
|
|
} else {
|
|
throw 'Could not launch $url';
|
|
}
|
|
}
|
|
|
|
Future<void> launchUniversalLinkIos(String url) async {
|
|
if (await canLaunchUrl(Uri.parse(url))) {
|
|
final bool nativeAppLaunchSucceeded = await launch(
|
|
url,
|
|
forceSafariVC: false,
|
|
universalLinksOnly: true,
|
|
);
|
|
if (!nativeAppLaunchSucceeded) {
|
|
await launchUrl(Uri.parse(url));
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> makePhoneCall(String url) async {
|
|
await launchUrl(Uri.parse('tel:$url'));
|
|
}
|
|
|
|
Future<void> textTo(String url, String body) async {
|
|
if (const LocalPlatform().isAndroid) {
|
|
var uri = 'sms:+$url?$body';
|
|
await launchUrl(Uri.parse(uri));
|
|
} else if (const LocalPlatform().isIOS) {
|
|
var uri = 'sms:00$url?$body';
|
|
await launchUrl(Uri.parse(uri));
|
|
}
|
|
}
|
|
}
|