【发布时间】:2019-06-19 07:40:49
【问题描述】:
我正在开发一个使用 http.request 方法读取数据的应用程序。如果设备在线,一切正常,但如果设备离线,它就会失去我的功能。
我的代码是这样的:
_fetchPost() async {
final response = await http.get('https://myUrl.com');
//if the device is offline it jumps all the code below
print("Hi"); //not printed
if (response.statusCode == 200) {
//do something
} else {
throw Exception('Failed to load'); //not throwed
}
}
【问题讨论】: