You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter使用url_launcher无法打开指定Messenger URL问题求助

Flutter中无法打开https://m.me/nagadhat链接的问题

我在Flutter应用里尝试启动链接「https://m.me/nagadhat」,但无法成功打开;该链接在浏览器及其他环境中均可正常访问。

使用的代码如下:

String chatURL = "https://m.me/nagadhat";
var url = Uri.parse(chatURL);
if (await canLaunchUrl(url)) {
  await launchUrl(url);
} else {
  throw 'Could not launch $url';
}

触发代码时的截图:
触发链接打开时的截图


解决方法

1. 配置url_launcher的平台权限

m.me是Facebook Messenger的专属链接,需要在对应平台配置支持的scheme:

  • Android端:在android/app/src/main/AndroidManifest.xml的<activity>标签内添加intent-filter:
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="https" android:host="m.me" />
    <data android:scheme="fb-messenger" />
</intent-filter>
  • iOS端:在ios/Runner/Info.plist中添加LSApplicationQueriesSchemes配置:
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fb-messenger</string>
    <string>https</string>
</array>

2. 修改launchUrl的启动模式

强制使用外部应用打开链接,避免Flutter内部处理异常:

String chatURL = "https://m.me/nagadhat";
var url = Uri.parse(chatURL);
if (await canLaunchUrl(url)) {
  await launchUrl(
    url,
    mode: LaunchMode.externalApplication, // 指定外部应用打开
  );
} else {
  throw 'Could not launch $url';
}

3. 确保url_launcher包为最新版本

在pubspec.yaml中更新依赖到最新版:

dependencies:
  url_launcher: ^6.2.5 # 替换为当前最新版本

完成以上配置后重新运行应用,若设备安装了Messenger会直接跳转至应用内聊天界面,未安装则会在浏览器中打开链接。

内容的提问来源于stack exchange,提问作者Istiak Ahmed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 18:35:36