flutter - http.dart onError : Invalid argument (onError): Error handler must accept one Object or one Object and a StackTrace as arguments 的无效参数

标签 flutter http dart

我是 Flutter 的新手,我想了解我的错误处理程序有什么问题:

import 'package:http/http.dart' as http;
try {
  var response = await client.get('$endpoint/users/$userId');

  // Convert and return
  return User.fromJson(json.decode(response.body));
} on HttpException catch (ex) {
  print('http');
  print(ex);
  print('exception');
  return null;
} on Error catch (error) {
  // code will go here
  print(error);
  return null;
}
结果是:
I/flutter ( 3103): Invalid argument (onError): Error handler must accept one Object or one Object and a StackTrace as arguments.: Closure: (HttpException) => Null
和我什么都没做完全一样try/catch ,谁能建议我应该如何做错误处理程序?据我了解(error)这里应该是“一个对象”,如果我错了,请纠正我。蒂亚!

最佳答案

这是一个 http依赖错误,它在 0.12.2 版本中得到修复,应该在您更新依赖时解决。

关于flutter - http.dart onError : Invalid argument (onError): Error handler must accept one Object or one Object and a StackTrace as arguments 的无效参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68992204/

相关文章:

http - SSL 不适用于 nginx 443 配置

canvas - drawImage 或 paintImage 在 Flutter 中无法正常工作

firebase - 如何使用 buildArguments 或其他任何东西在 Flutter/FirebaseAnimatedList 中查询? (请举例)

flutter - 带圆角的方形进度条

flutter - 动态导航路线

android - Flutter:如何禁用 `showDatePicker` 中的过去日期?

c++ - 仅处理逻辑的 C/C++ HTTP 库?

python - 将 Python “requests” 与现有套接字连接一起使用

ios - 在Flutter中安装 native iOS Pod

firebase - 如何按当前日期从 Cloud Firestore 获取数据?