skip to Main Content

im trying to link whatsapp with this function, i already try many url options but nothing works

    static Future launchThisUrl(url) async {
    Uri dataUrl = Uri.parse(url!);

    if (await canLaunchUrl(dataUrl)) {
      await launchUrl(dataUrl);
    } else {
      throw 'Could not launch $dataUrl';
    }
  }

  static launchWhatsApp(
      {required String phone, required String message}) async {
    String url = '';
    if (Platform.isAndroid) {
      url = "https://wa.me/$phone?text=${Uri.parse(message)}";
      log('ANDROID == $url');
    } else {
      log('IOS');
      url = "https://wa.me/send?phone=$phone&text=${Uri.parse(message)}";
    }
    await launchThisUrl(url);
  }

but it always return this

enter image description here

2

Answers


  1. The url in my case that works, looks like this. Try this:

    https://wa.me/${phone}/?text=hello
    
    Login or Signup to reply.
  2. Maybe this can help you:

    import 'package:whatsapp_unilink/whatsapp_unilink.dart';
    import 'package:url_launcher/url_launcher.dart';
    
            final link = WhatsAppUnilink(
              phoneNumber: '+000000000',
              text: "hello",
            );
        
            await launch('$link');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search