如下所示,代码包含一个按钮,单击该按钮将Cloud中的数据作为消息发送到WhatsApp上,使用包'whatsapp_unilink‘和'url_launcher'/
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');
});
},
),上面的代码返回以下内容
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这意味着它为每个数据(链接)分别生成一个(这不是我的目标),目标是让将所有数据放在一个消息(链接)中,然后将其发送给接收方,如下所示:
那我该怎么做呢?
请注意,这个问题与电话号码无关,它只是一个假号码!
发布于 2022-08-13 14:01:41
创建一个空字符串。将值添加到in循环中,然后在完成后发送消息。
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');
},
),https://stackoverflow.com/questions/73344772
复制相似问题