我的项目在调试模式下可以正常运行,但发布后,除一个过程外,其他所有功能都可以运行。
以下是过程:
Future<void> downloadFile() async{
Dio dio = Dio();
var directory = await getApplicationDocumentsDirectory();
await dio.download(bookUrl, "${directory.path}/$className + $bookName.pdf",
onReceiveProgress: (rec, total){
setState(() {
downloading = true;
percentage = ((rec/total) * 100).toStringAsFixed(0)+'%';
});
}
);
setState(() {
downloading = false;
percentage = 'Download Completed';
});
}
这是发布应用程序运行时出现的错误消息:
E / flutter(25796):[错误:flutter / lib / ui / ui_dart_state.cc(148)] 未处理的异常:DioError [DioErrorType.DEFAULT]:SocketException: 主机查找失败:“ www.ets.org”(操作系统错误:未关联地址 主机名errno = 7)E / flutter(25796):#0 Dio._makeRequest (包装:dio / src / dio.dart:799)E / flutter(25796):E / flutter(25796):#1 Dio._request ..(package:dio / src / dio.dart:711)E / flutter (25796):#2 _rootRunUnary(dart:async / zone.dart:1132)E / flutter (25796):#3 _CustomZone.runUnary(dart:async / zone.dart:1029) E / flutter(25796):#4 _FutureListener.handleValue (dart:async / future_impl.dart:126)E / flutter(25796):#5
Future._propagateToListeners.handleValueCallback (dart:async / future_impl.dart:639)E / flutter(25796):#6
Future._propagateToListeners(dart:async / future_impl.dart:668) E / flutter(25796):#7 Future._complete (dart:async / future_impl.dart:473)E / flutter(25796):#8
_SyncCompleter.complete(dart:async / future_impl.dart:51)E / flutter(25796):#9 _AsyncAwaitCompleter.complete。 (dart:async-patch / async_patch.dart:33)E / flutter(25796):#10
_rootRun(dart:async / zone.dart:1120)E / flutter(25796):#11 _CustomZone.run(dart:async / zone.dart:1021)E / flutter(25796):#12 _CustomZone.runGuarded(dart: async / zone.dart:923)E / flutter(25796):#13 _CustomZone.bindCallbackGuarded。 (dart:async / zone.dart:963)E / flutter(25796):#14 _rootRun (dart:async / zone.dart:1124)E / flutter(25796):#15 _CustomZone.run (dart:async / zone.dart:1021)E / flutter(25796):#16
_CustomZone.runGuarded(dart:async / zone.dart:923)E / flutter(25796):#17 _CustomZone.bindCallbackGuarded。 (dart:async / zone.dart:963)E / flutter(25796):#18 _microtaskLoop (dart:async / schedule_microtask.dart:41)E / flutter(25796):#19
_startMicrotaskLoop(dart:async / schedule_microtask.dart:50)
答案 0 :(得分:3)
确保您拥有
<uses-permission android:name="android.permission.INTERNET" />
在您应用的android / app / src / main / AndroidManifest.xml中
答案 1 :(得分:0)
SocketException:主机查找失败:'www.ets.org'(操作系统错误:否 与主机名相关的地址errno = 7)
似乎您无法连接到该主机。可能是您需要应用程序的网络权限吗?
编辑:有关特定代码行,请参见以下OP的答案:https://stackoverflow.com/a/56921201/679553