如何防止 flutter 应用程序在 Dio 错误后崩溃?
How to prevent flutter app from crashing after Dio error?
我正在使用 flutter-dio
包来发出 HTTP 请求,并在我方便的时候对它进行了包装,就像这样
Future<dynamic> post(String uri, dynamic body, {String authKeyCust}) async {
authKey = await SecureStorage.getAuthKey();
try {
Response response = await dio.post(
uri,
data: body,
options: Options(headers: {"authkey": authKeyCust ?? "$authKey"}),
);
return response.data;
} on DioError catch (error) {
print('error: $error');
} on SocketException catch(error) {
print('No net');
}
}
我想要的只是应用程序在发生任何错误时不crash/pause异常。
我也遇到了同样的问题
首先,尝试从命令提示符 flutter run
运行 它,看看是否出现任何问题。
如果命令提示符没有显示问题并且您的应用 运行 运行顺利,那么您必须检查 IDE。如果您使用 VSCode 然后切换到 Debug is side bar,查看在 Breakpoint 部分中勾选了哪些选项。
如果勾选 All Exceptions
则调试器将在每次异常时暂停。取消选中 All Exceptions
和 Uncaught Exceptions
然后尝试刷新重启。
希望这能解决您的问题。
我正在使用 flutter-dio
包来发出 HTTP 请求,并在我方便的时候对它进行了包装,就像这样
Future<dynamic> post(String uri, dynamic body, {String authKeyCust}) async {
authKey = await SecureStorage.getAuthKey();
try {
Response response = await dio.post(
uri,
data: body,
options: Options(headers: {"authkey": authKeyCust ?? "$authKey"}),
);
return response.data;
} on DioError catch (error) {
print('error: $error');
} on SocketException catch(error) {
print('No net');
}
}
我想要的只是应用程序在发生任何错误时不crash/pause异常。
我也遇到了同样的问题
首先,尝试从命令提示符 flutter run
运行 它,看看是否出现任何问题。
如果命令提示符没有显示问题并且您的应用 运行 运行顺利,那么您必须检查 IDE。如果您使用 VSCode 然后切换到 Debug is side bar,查看在 Breakpoint 部分中勾选了哪些选项。
如果勾选 All Exceptions
则调试器将在每次异常时暂停。取消选中 All Exceptions
和 Uncaught Exceptions
然后尝试刷新重启。
希望这能解决您的问题。