问题
when in debug mode everything looks good, get response and lists of data from my API. But after I build app-release.apk and install to my phone, it shows no internet connection
here is my code
ScopedModelDescendant<ReportPosViewModel>(
builder: (context, child, model) {
return FutureBuilder<List<Invoice>>(
future: model.invoices,
builder: (_,
AsyncSnapshot<List<Invoice>> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.active:
case ConnectionState.waiting:
return Center(
child:
const CircularProgressIndicator());
case ConnectionState.done:
if (snapshot.hasData) {
//something todo
} else if (snapshot.hasError) {
return NoInternetConnection(
action: () async {
await model.setInvoice();
await getData();
},
);
}
}
},
);
},
),
回答1:
In the AndroidManifest.xml
file located at android/app/src/main
you need to add this permission in <manifest
tag.
<uses-permission android:name="android.permission.INTERNET"/>
回答2:
add to android/app/src/main/AndroidManifest.xml after package name
回答3:
If you had put
<uses-permission android:name="android.permission.INTERNET"/>
on AndroidManifest.xml
And If it's not working
Try checking connectivity of device. Mobile data or WiFi on android device. Try using chrome browser for google search If it's not working
allow
8.8.8.8
in DNS setting of computer you are using.
来源:https://stackoverflow.com/questions/55603979/why-flutter-application-cant-connect-to-internet-when-install-app-release-apk