android 9 上的 Flutter WebView 插件错误

Flutter WebView Plugin error on android 9

我正在开发一个 android 应用程序,它有一个 Flutter WebView 插件来显示网页。它在我的 phone (Android 8.1 LG V20) 上完美运行。但是在我的朋友 phone (Android 9 xiaomi note 7 pro) 上它显示了这个错误:

我的代码:flutter_webview_plugin: ^0.3.8

 import 'package:flutter/material.dart';
 import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

 class WebPage extends StatefulWidget {
  final String url;

  WebPage({
    this.url,
  });
  @override
  _WebPageState createState() => _WebPageState();
}

class _WebPageState extends State<WebPage> {
  @override
  void initState() {
    super.initState();
    print('url = ' + widget.url);
  }
  @override
  Widget build(BuildContext context) {
    String link = widget.url;
    return WebviewScaffold(
      url: link,
      appBar: new AppBar(
        centerTitle: true,
        backgroundColor: Colors.green,
      ),
      displayZoomControls: true,
    );
  }
}

如有任何帮助,我们将不胜感激。

你的朋友看到​​这个错误是因为 Android 9 及更高版本的标准是连接到 http 域是非法的,Google 认为它不安全。
相反,您有 3 个选项。

https

使用您网站的 https 变体。
而不是加载 http://window.arian.co.ir 加载 https://window.arian.co.ir

选择退出您的域。

您可以选择退出 window.arian 域的安全检查。

创建一个名为 network_security_config.xml 的文件并将其放在 android 文件夹的 res/xml/ 文件夹中。

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">window.arian.co.ir</domain>
    </domain-config>
</network-security-config>

完全退出

如果您愿意,可以通过将 android:usesCleartextTraffic="true" 放在 Application 标签上来选择不对 WebView 内的所有站点进行此安全检查。

在您的 android 文件夹中导航到 AndroidManifest.xml

<application
        android:name="io.flutter.app.FlutterApplication"
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="true">

查看文档: