为什么Flutter应用在安装“app-release.apk"时无法上网?但它在调试模式下正常工作 [英] 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 并将其安装到我的手机上后,互联网连接不再存在.
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>
来自这里:
如果您的应用程序代码需要访问互联网,请添加 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.
这篇关于为什么Flutter应用在安装“app-release.apk"时无法上网?但它在调试模式下正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!