我无法捕捉SocketException
颤振http
包。
Future<User> getUserDetail(String token) async {
try {
final response = await http.get(Uri.parse(userURL), headers: {
'Accept': 'application/json',
'Authorization': 'Bearer $token'
});
return User.fromJson(jsonDecode(response.body));
// this catch does not catch SocketException
} catch(e) {
print('Error catched: $e');
}
}
当模拟器处于飞行模式或无法访问本地服务器时,我会遇到这个问题。否则一切正常。所以我的问题是,为什么我无法捕捉到这些异常?
我的颤振版本是 2.0.5flutter doctor
并且cleartextTraffic = "true"
在AndroidManifiest.xml
.
更新flutter2.0.5
以2.2.0
解决问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句