How to fix 'net::ERR_CLEARTEXT_NOT_PERMITTED' in flutter

前端 未结 5 1675
情话喂你
情话喂你 2020-12-20 12:49

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 integra

相关标签:
5条回答
  • 2020-12-20 12:57

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

    <application
    ....
    android:usesCleartextTraffic="true"
    ....>
    
    0 讨论(0)
  • 2020-12-20 12:57

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

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

    it not working in android version 9

    0 讨论(0)
  • 2020-12-20 12:59

    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">
    
    0 讨论(0)
  • 2020-12-20 13:05

    In main directory of your Flutter project you have three main folders:

    - lib         =  your Dart code
    - ios         =  generated structure for iOS platform
    - android     =  generated structure for Android platform
    

    We are interested in android directory. When you open it, you will see "typical Android app structure".

    So you have to do 2 things:

    1) Add new file in res

    Go to directory:

    my_flutter_project/android/app/src/main/res/
    

    Create xml directory (in res!)

    And inside xml add new file with name: network_security_config.xml and content:

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

    network_security_config.xml should be located in path:

    my_flutter_project/android/app/src/main/res/xml/network_security_config.xml
    

    Here you can find more information about this file:

    https://developer.android.com/training/articles/security-config

    2) Modify AndroidManifest.xml

    Go to:

    flutter_project/android/app/src/main/AndroidManifest.xml
    

    AndroidManifest.xml is XML file, with structure:

    <manifest>
        <application>
            <activity>
                ...
            </activity>
            <meta-data >
        </application>
    </manifest>
    

    So for <application> PROPERTIES you have to add 1 line:

    android:networkSecurityConfig="@xml/network_security_config"
    

    Remember that you have to add it as property (inside application opening tag):

    <application
    
        SOMEWHERE HERE IS OK
    
    >
    

    Not as a tag:

    <application>           <--- opening tag
    
        HERE IS WRONG!!!!
    
    <application/>          <--- closing tag
    
    0 讨论(0)
  • 2020-12-20 13:21
    • 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.
    0 讨论(0)
提交回复
热议问题