Files
tripz/lib/controller/functions/launch.dart
Hamza-Ayed 6f3c8b975e 5/27/1
2024-05-27 13:21:14 +03:00

67 lines
1.6 KiB
Dart

import 'package:url_launcher/url_launcher.dart';
import 'dart:io';
void showInBrowser(String url) async {
if (await canLaunchUrl(Uri.parse(url))) {
launchUrl(Uri.parse(url));
} else {
print('Could not launch $url');
}
}
void launchCommunication(
String method, String contactInfo, String message) async {
String url;
// Encode the message
String encodedMessage = Uri.encodeComponent(message);
if (Platform.isIOS) {
switch (method) {
case 'phone':
url = 'tel:$contactInfo';
break;
case 'sms':
url = 'sms:$contactInfo?body=$encodedMessage';
break;
case 'whatsapp':
url =
'https://api.whatsapp.com/send?phone=$contactInfo&text=$encodedMessage';
break;
case 'email':
url = 'mailto:$contactInfo?subject=Subject&body=$encodedMessage';
break;
default:
print('Method not supported on iOS');
return;
}
} else if (Platform.isAndroid) {
switch (method) {
case 'phone':
url = 'tel:$contactInfo';
break;
case 'sms':
url = 'sms:$contactInfo?body=$encodedMessage';
break;
case 'whatsapp':
url = 'whatsapp://send?phone=$contactInfo&text=$encodedMessage';
break;
case 'email':
url = 'mailto:$contactInfo?subject=Subject&body=$encodedMessage';
break;
default:
print('Method not supported on Android');
return;
}
} else {
print('Platform not supported');
return;
}
if (await canLaunch(url)) {
await launch(url);
} else {
print('Could not launch $url');
}
}