6.0.4 url_launcher无法打开网页

来源:6-10 如何打开第三方应用?【你期待的技能】

慕村0493939

2021-05-25

看了一下提问有类似的问题但是也没有解答,下面是我的源码,仿插件example写的

class _LaunchPageState extends State<LaunchPage> {
  Future<void>? _launched;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('如何打开第三方应用'),
        leading: GestureDetector(
          onTap: () {
            Navigator.pop(context);
          },
          child: Icon(Icons.arrow_back),
        ),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
                onPressed: () => setState(() {
                  _launched = _launchInWebViewOrVC('https://www.baidu.com');
                }),
                child: Text('打开百度'))
          ],
        ),
      ),
    );
  }
 Future<void> _launchInWebViewOrVC(String url) async {
    if (await canLaunch(url)) {
      await launch(
        url,
        forceSafariVC: true,
        forceWebView: true,
        headers: <String, String>{'my_header_key': 'my_header_value'},
      );
    } else {
      throw 'Could not launch $url';
    }
  }

按了没反应,debug要怎么做,打个断点吗

写回答

2回答

布罗利00

2021-10-11

ios的话 配置下这个试下

iOS 

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

Example:

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


0
0

CrazyCodeBoy

2021-06-08

有可能是当前设备无法打开这个网页,用真机试一下看能否正常打开

0
0

Flutter从入门到进阶 实战携程网App 一网打尽核心技术

解锁Flutter开发新姿势,,系统掌握Flutter开发核心技术。

4788 学习 · 3274 问题

查看课程