How to fix 'net::ERR_CLEARTEXT_NOT_PERMITTED' in flutter

醉酒当歌 提交于 2019-12-18 08:54:01

问题


I have implemented webView in flutter but it is not opening my php website which is on server what I'm doing wrong.

I am new to flutter and tried webview to integrate my website webpage in my application but no luck.

Widget build(BuildContext context) {
    // TODO: implement build
    return WebviewScaffold(
      appBar: AppBar(iconTheme:IconThemeData(color: Colors.white),title: Text("Intake Form",style:new TextStyle(color: Colors.white,fontWeight: FontWeight.bold)),backgroundColor:Colors.indigoAccent,automaticallyImplyLeading: false),
     url: url,
      //url: "http://61.246.39.79:8080/",
       withJavascript: true,
       supportMultipleWindows: true,
      withLocalStorage: true,
      allowFileURLs: true,
      enableAppScheme: true,
      appCacheEnabled: true,
      hidden: false,
      scrollBar: true,
      geolocationEnabled: false,
      clearCookies: true,
       // usesCleartextTraffic="true"



    );
  }

I expect the output as running webview but error is thrown.


回答1:


set usesCleartextTraffic property to true in your AndroidManifest file, like below.

<application
....
android:usesCleartextTraffic="true"
....>



回答2:


Open the android manifest file (android/app/src/main/AndroidManifest.xml) and add

android:usesCleartextTraffic="true" to the application tag

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



回答3:


In AndroidManifest.xml, add [android:usesCleartextTraffic="true"] as

<application
    ......
    .......
    android:usesCleartextTraffic="true"
    .............. >
    <.........
        ................... />

            ..........
    ...........>
</application>

it not working in android version 9




回答4:


  • make network_security_config.xml file.

<?xml version="1.0" encoding="utf-8"?>
        <network-security-config>
            <base-config cleartextTrafficPermitted="true">
                <trust-anchors>
                    <certificates src="system" />
                </trust-anchors>
            </base-config>
        </network-security-config>

  • add this two line in Manifest file in Application tag.


来源:https://stackoverflow.com/questions/55592392/how-to-fix-neterr-cleartext-not-permitted-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!