擅长:python、mysql、java
<p>将网络呼叫包围在try-catch块中</p>
<pre><code>Future<String> uploadImage(PickedFile file) async {
print('calling');
Dio dio = new Dio();
String fileName = file.path.split('/').last;
FormData formData = FormData.fromMap({
"file": await MultipartFile.fromFile(file.path,
filename: fileName, contentType: new MediaType("image", "jpeg")),
});
try{
var response = await dio.post("https://count-
object.herokuapp.com/upload",
data: formData);
print(response.data['id']);
return response.data['id'];
} on DioError catch(e){
throw Exception(e.response?.data);
}
}
</code></pre>
<p><code> throw Exception(e.response?.data);</code>这将提示您出了什么问题</p>