为什么在安装"app-release.apk"时Flutter应用程序无法连接到Internet?但是它可以在调试模式下正常工作 [英] Why can't a Flutter application connect to the Internet when installing "app-release.apk"? But it works normally in debug mode
问题描述
在调试模式下,一切看起来都不错.我从我的API获得答案和数据列表.但是在创建 app-release.apk 并将其安装在我的手机上之后,就不再有Internet连接了.
In debug mode, everything looks good. I get answers and data lists from my API. But after creating app-release.apk and installing it on my phone, there isn't an Internet connection any more.
这是我的代码:
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();
},
);
}
}
},
);
},
),
推荐答案
打开位于 ./android/app/src/main
的 AndroidManifest.xml
文件并添加以下行:
Open the AndroidManifest.xml
file located at ./android/app/src/main
and add the following line:
<manifest xmlns:android="...">
<uses-permission android:name="android.permission.INTERNET"/> <!-- Add this -->
</manifast>
从此处:
如果您的应用程序代码需要Internet访问,请添加android.permission.INTERNET权限.标准模板不包含此标签,但允许在开发过程中访问Internet,以实现Flutter工具与正在运行的应用之间的通信.
Add the android.permission.INTERNET permission if your application code needs Internet access. The standard template does not include this tag but allows Internet access during development to enable communication between Flutter tools and a running app.
这篇关于为什么在安装"app-release.apk"时Flutter应用程序无法连接到Internet?但是它可以在调试模式下正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!