Flutter Url Launcher 不会将整个文本传递给短信

Kar*_*dts 1 dart flutter

我正在尝试使用 flutter 中的包 url 启动器发送短信。当我按下按钮时:只有这个出现在短信正文中(在Android上):https://www.google.com/maps/dir/?api =1

但“文本”有点长。有解决办法吗?谢谢!

RaisedButton(
              onPressed: () {
                launch(
                    'sms:000000000?body=https://www.google.com/maps/dir/?api=1&destination=47.751076,-120.740135');
              },
Run Code Online (Sandbox Code Playgroud)

我测试了没有“&”符号的链接。比它通过了一切。是否可以选择使用 & 符号?

anm*_*ail 7

您需要对 URL 中的特殊字符使用 URL 编码。

所以&等于%26

这会起作用

launch('sms:000000000?body=https://www.google.com/maps/dir/?api=1%26destination=47.751076,-120.740135');
Run Code Online (Sandbox Code Playgroud)

其他方式是编码并通过Uri.encodeFull(urlString)Uri.encodeComponent(urlString)

像这样。

launch("sms:" + Uri.encodeComponent('000000000?body=https://www.google.com/maps/dir/?api=1&destination=47.751076,-120.740135'));
Run Code Online (Sandbox Code Playgroud)