You may encounter "ERR_CLEARTEXT_NOT_PERMITTED" error when you try to open a web page with a non-secure connection (such as HTTP connection instead of HTTPS connection) in your Flutter application. This is because by default, Android 9 and higher prohibits applications from communicating over the network over non-secure clear-text HTTP connections.
To fix this, you can take one of three approaches:
Method 1: Use a secure HTTPS connection
- Migrate your web pages to use HTTPS connections. This is a more secure way to connect and will not trigger the "ERR_CLEARTEXT_NOT_PERMITTED" error.
Method 2: Configure network security
- Create an xml directory and an XML file named `network_security_config.xml` under the `android/app/src/main/res` directory of the Flutter project.
- Add the following to the `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 the following lines under the `application` tag in the `android/app/src/main/AndroidManifest.xml` file:
android:networkSecurityConfig="@xml/network_security_config"
Solution 3 Add usesCleartextTraffic under `application` tag
Add the following lines under the `application` tag in the `android/app/src/main/AndroidManifest.xml` file:
android:usesCleartextTraffic="true"
- Save the file and recompile the Flutter app.
Your Flutter app should now be able to open web pages over non-secure connections. But please note that non-secure connections (HTTP) may have security risks, so we still recommend using HTTPS connections to protect the security of user data.
Additional: If Webview error net:ERR_CACHE_MISS
Add network permission in android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
Create value, happy to share! 776147358