gpt4 book ai didi

flutter - 为什么 flutter 在 url 启动器中给我 url null ?

转载 作者:行者123 更新时间:2023-12-03 08:07:30 25 4
gpt4 key购买 nike

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

最佳答案

添加每个平台的查询,请按照此链接 URL Launcher API Reference 中的文档进行操作

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。必须将元素作为根元素的子元素添加到 list 中。

<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>

这对我有用!

关于flutter - 为什么 flutter 在 url 启动器中给我 url null ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71730452/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com