launcherUrl method
dynamic
launcherUrl({})
Implementation
launcherUrl(
{String? url,
String? phone,
String? mail,
BuildContext? context,
bool? openSafari,
bool? openbrowser}) async {
if (phone != null) {
final Uri launchUri = Uri(
scheme: 'tel',
path: phone,
);
await launchUrl(launchUri);
// await launch(launchUri.toString());
}
if (mail != null) {
final Uri params = Uri(
scheme: 'mailto',
path: mail,
);
String url = params.toString();
Uri url2 = Uri.parse(url);
if (await canLaunchUrl(url2)) {
await launchUrl(url2);
} else {
// print('Could not launch $url');
}
}
if (url != null) {
if (url.contains("tel:.//") || url.contains("mailto:")) {
Uri url2 = Uri.parse(url);
if (await canLaunchUrl(url2)) {
await launchUrl(url2);
} else {
throw 'Could not launch $url';
}
} else if (url.contains("sellon.net/product_detail/") ||
url.contains("sellon.net/shop/")) {
// String newUrl = url.replaceAll("${sellonConfig.ConfignationCode}", "");
// url = newUrl;
String id = url.split("/").last;
// if (url.contains("product_detail")) {
// SellonRouter.push(
// context!,
// DetailProductScreen(
// id: id,
// ));
// } else {
// SellonRouter.push(
// context!,
// MyShopScreen(
// userId: id,
// ));
// }
} else {
if (!url.contains("http")) {
url = "https://" + url;
if (url.contains("sellon.net/product_detail/") ||
url.contains("sellon.net/shop/")) {
String newUrl =
url.replaceAll("${Config.nationCode}", "");
url = newUrl;
}
}
if (await canLaunch(url)) {
if (openbrowser != null) {
await launchUrl(Uri.parse(url),
mode: LaunchMode.externalApplication);
} else {
if (Platform.isIOS) {
if (openSafari != null) {
_launchUniversalLinkIos(Uri.parse(url));
} else {
await launchUrl(Uri.parse(url), mode: LaunchMode.inAppWebView);
}
} else {
await launchUrl(Uri.parse(url), mode: LaunchMode.inAppWebView);
}
}
// await launch(url,);
} else {
throw 'Could not launch $url';
}
}
}
// const url = 'https://flutter.dev';
// if (!url.contains("www")){
// url = "www."+url;
// }else
}