1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Manage Whatsapp/Whatsapp business links on flutter

Discussão em 'Mobile' iniciado por Stack, Outubro 4, 2024 às 07:22.

  1. Stack

    Stack Membro Participativo

    I'm working on a Flutter app and need your help to improve the handling of WhatsApp links. Currently, when I click on a phone number, a bottom sheet (or popup) appears asking if I want to use the dialer or WhatsApp. However, when I choose WhatsApp, it opens a page in the browser and then (on some devices, but not on others) an Android popup that lets me choose between WhatsApp and WhatsApp Business.

    This behavior is inconsistent across different devices, and I want to avoid the browser step, as it might confuse less tech-savvy users (which is the majority of my app's users).

    My goal is to make it so that when I press "WhatsApp," a dialog appears directly that allows me to choose between WhatsApp and WhatsApp Business, with the option to do it "only once" or "always." I want to avoid forcing users to change their Android settings to select the default WhatsApp app.

    Here’s the code I’m currently using to handle WhatsApp and that is not working as intended:

    void _launchWhatsApp(String phoneNumber) async {
    const whatsappBusinessScheme = 'whatsapp://send?phone=';
    const whatsappScheme = 'https://wa.me/';

    final Uri whatsappBusinessUri =
    Uri.parse('$whatsappBusinessScheme$phoneNumber');
    if (await canLaunchUrl(whatsappBusinessUri)) {
    await launchUrl(whatsappBusinessUri);
    } else {
    final Uri whatsappUri = Uri.parse('$whatsappScheme$phoneNumber');
    if (await canLaunchUrl(whatsappUri)) {
    await launchUrl(whatsappUri);
    } else {
    Get.snackbar('error'.tr, 'whatsapp_error'.tr);
    }
    }
    }


    Do I need to add something in the AndroidManifest or info.plist? Or is there something I'm missing? Does anyone have suggestions on how to implement this functionality without going through the browser? Any help would be greatly appreciated!

    Thanks in advance!

    Continue reading...

Compartilhe esta Página