'Flutter app only working with WiFi and not mobile data
I have a flutter app that is working fine with WiFi but when I switch to mobile data its not working. I have checked and I have internet connection because my other sites and apps are working.
On the Android side I have in my manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Then inside the application tag:
<meta-data android:name="io.flutter.network-policy"
android:resource="@xml/network_security_config"/>
Then inside the network_security_config.xml file I have:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">www.mydomain.com</domain>
</domain-config>
</network-security-config>
I am using a package nb_utils and under the hood it uses connectivity_plus to check for internet connection and to check for connectivity I have:
ConnectivityResult connectivityResult = await (Connectivity().checkConnectivity());
if (connectivityResult == ConnectivityResult.mobile) {
print('I have Data access');
return true;
} else if (connectivityResult == ConnectivityResult.wifi) {
print('I have WIFI access');
return true;
}
print('I have NO access');
return false;
And I am getting 'I have Data access' printed in the console when I am connected to mobile data.
At first I was using http://shop.mydomain.com on my URI but then I had to apply an SSL certificate on my domain to see if its working but still got the same thing using https://shop.mydomain.com. I am not getting any error(s) in my console as well. I havent tried this on iOS as yet, I have only added:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
in the Info.plist.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
