launchLink function
void
launchLink({
- required BuildContext context,
- required LaunchLinkType launchLinkType,
- String? account,
- String? url,
- String? message,
- Map<
String, String> headers = const <String, String>{},
Implementation
void launchLink({
required BuildContext context,
required LaunchLinkType launchLinkType,
String? account,
String? url,
String? message,
Map<String, String> headers = const <String, String>{},
}) async {
dynamic _url = launchLinkType == LaunchLinkType.genericLink
? url.toString()
: launchLinkType == LaunchLinkType.whatsApp
? "https://wa.me${![
'',
null
].contains(account) ? '/55${account?.replaceAll(RegExp(r'[^0-9]'), '')}' : ''}/?text=${Uri.encodeComponent(message.toString())}"
: 'https://${launchLinkType == LaunchLinkType.instagram ? 'instagram' : 'facebook'}.com/$account';
bool? _canLaunch;
if ([
LaunchLinkType.facebook,
LaunchLinkType.instagram,
].contains(launchLinkType)) {
_canLaunch = await canLaunch(_url.toString());
} else {
_canLaunch = true;
}
if (_canLaunch) {
await launch(
_url,
universalLinksOnly: true,
headers: headers,
);
} else {
showDialog(
context: context,
builder: (BuildContext context) {
return const AlertDialog(
title: Text("Erro ao acessar o perfil"),
content: Text("App não instalado."),
);
},
);
}
}