首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用包whatsapp_unilink在单个文本消息中传递多个数据

如何使用包whatsapp_unilink在单个文本消息中传递多个数据
EN

Stack Overflow用户
提问于 2022-08-13 13:39:49
回答 1查看 46关注 0票数 0

如下所示,代码包含一个按钮,单击该按钮将Cloud中的数据作为消息发送到WhatsApp上,使用包'whatsapp_unilink‘和'url_launcher'/

代码语言:javascript
复制
String? product;
String? qnty;

Cbutton(
    text: 'Whatsapp',
    onPressed: () async {
      snapshot.data.docs
          .forEach((value) async {
        product = value.data()['Product'];
        qnty = _controller.text;
        print(product);
        final link = WhatsAppUnilink(
          phoneNumber: '+914534534553',
          text: '- $product = $qnty \n',
        );
   
        await launch('$link');
        print('$link');
      });
    },
),

上面的代码返回以下内容

代码语言:javascript
复制
I/flutter (20941): ASHNIL SYRUP (200ML)
I/flutter (20941): OLSEPT PLUS MW GARGLE 
I/flutter (20941): https://wa.me/912342424344?text=-%20ASHNIL%20SYRUP%20(200ML)%20%3D%203%20%0A
I/flutter (20941): https://wa.me/912423423444?text=-%20OLSEPT%20PLUS%20MW%20GARGLE%20%20%3D%203%20%0A

这意味着它为每个数据(链接)分别生成一个(这不是我的目标),目标是让将所有数据放在一个消息(链接)中,然后将其发送给接收方,如下所示:

https://wa.me/912342424344?text=-%20ASHNIL%20SYRUP%20(200ML)%20%3D%203%20%0A-%20OLSEPT%20PLUS%20MW%20GARGLE%20%20%3D%203%20%0A

那我该怎么做呢?

请注意,这个问题与电话号码无关,它只是一个假号码!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-13 14:01:41

创建一个空字符串。将值添加到in循环中,然后在完成后发送消息。

代码语言:javascript
复制
Cbutton(
    text: 'Whatsapp',
    onPressed: () async {
     String message = "";
      snapshot.data.docs
          .forEach((value) async {
        product = value.data()['Product'];
        qnty = _controller.text;
        print(product);
        message +='- $product = $qnty \n';
      });
     final link = WhatsAppUnilink(
          phoneNumber: '+914534534553',
          text: message
        );
   
        await launch('$link');
    },
),
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73344772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档