import 'package:url_launcher/url_launcher.dart';

void launchUrl1(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;

  switch (method) {
    case 'phone':
      url = 'tel:$contactInfo';
      break;
    case 'sms':
      url = 'sms:$contactInfo?body=$message';
      break;
    case 'whatsapp':
      url = 'whatsapp://send?phone=$contactInfo&text=$message';
      break;
    case 'email':
      url = 'mailto:$contactInfo?subject=Subject&body=$message';
      break;
    default:
      print('Invalid communication method');
      return;
  }

  if (await canLaunchUrl(Uri.parse(url))) {
    launchUrl(Uri.parse(url));
  } else {
    print('Could not launch $url');
  }
}
