为什么在URL启动器中扑出我的URL null?

发布于 2025-01-18 17:59:56 字数 398 浏览 1 评论 0原文

ElevatedButton(
  onPressed: () async {
    const url ='https://www.facebook.com';

    if (await canLaunch(url)) {
      await launch(url,forceWebView: true,enableJavaScript: true);
    } else {
      // can't launch url
    }
  },
);
I/UrlLauncher( 7566): component name for https://www.facebook.com is null
ElevatedButton(
  onPressed: () async {
    const url ='https://www.facebook.com';

    if (await canLaunch(url)) {
      await launch(url,forceWebView: true,enableJavaScript: true);
    } else {
      // can't launch url
    }
  },
);
I/UrlLauncher( 7566): component name for https://www.facebook.com is null

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸵鸟症 2025-01-25 17:59:56

添加每个平台的查询,请按照此链接中的文档 url启动器API参考

ios
将传递给CanlaunchUrl的所有URL方案添加为您的Info.plist文件中的lsapplicationqueriesschemes条目。

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>https</string>
  <string>http</string>
</array>

Android
从API 30开始,Android需要您的AndroidManifest.xml中的包装可见性配置,否则CanlaunchUrl将返回false。作为根元素的孩子,必须将元素添加到您的清单中。

<queries>
  <!-- If your app opens https URLs -->
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="https" />
  </intent>
  <!-- If your app makes calls -->
  <intent>
    <action android:name="android.intent.action.DIAL" />
    <data android:scheme="tel" />
  </intent>
  <!-- If your sends SMS messages -->
  <intent>
    <action android:name="android.intent.action.SENDTO" />
    <data android:scheme="smsto" />
  </intent>
  <!-- If your app sends emails -->
  <intent>
    <action android:name="android.intent.action.SEND" />
    <data android:mimeType="*/*" />
  </intent>
</queries>

这对我有用!

Add the queries for each platform, follow the documentation in this link URL Launcher API Reference

iOS
Add any URL schemes passed to canLaunchUrl as LSApplicationQueriesSchemes entries in your Info.plist file.

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>https</string>
  <string>http</string>
</array>

Android
Starting from API 30 Android requires package visibility configuration in your AndroidManifest.xml otherwise canLaunchUrl will return false. A element must be added to your manifest as a child of the root element.

<queries>
  <!-- If your app opens https URLs -->
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="https" />
  </intent>
  <!-- If your app makes calls -->
  <intent>
    <action android:name="android.intent.action.DIAL" />
    <data android:scheme="tel" />
  </intent>
  <!-- If your sends SMS messages -->
  <intent>
    <action android:name="android.intent.action.SENDTO" />
    <data android:scheme="smsto" />
  </intent>
  <!-- If your app sends emails -->
  <intent>
    <action android:name="android.intent.action.SEND" />
    <data android:mimeType="*/*" />
  </intent>
</queries>

This works for me!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文