尝试使用dart将图像上传到flutter中的服务器 [英] Trying to upload the image to server in the flutter using dart
本文介绍了尝试使用dart将图像上传到flutter中的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Flutter开发的新手.我的问题是,当我尝试将图像上传到服务器时,出现以下错误:
I am new to Flutter development. My problem is that when I try to upload the image to the server I am getting following error:
NoSuchMethodError: The getter 'body' was called on null.
Receiver: null
Tried calling: body
这是我的代码:
var response;
var booking_info_url='http://18.207.188.4/ruralpost/api/api.php?action=booking';
http.post(booking_info_url,body: {"userid":"3","weight":"20","quantity":"1","bimage":base64UrlEncode(await _image.readAsBytesSync())}).then(response);
{
print("Response body: ${response.body}");
}
推荐答案
在您的代码中,您有两个不同版本的 response
,具有不同的范围,这不是您想要的.在 then
的正文之前删除"var response"和;
.
In your code you have two different versions of response
, with different scopes, which isn't what you intend. Remove the 'var response' and the ;
before the body of the then
.
String booking_info_url =
'http://18.207.188.4/ruralpost/api/api.php?action=booking';
http.post(booking_info_url, body: {
"userid": "3",
"weight": "20",
"quantity": "1",
"bimage": base64UrlEncode(await _image.readAsBytesSync())
}).then((Response response) {
print("Response body: ${response.body}");
});
这篇关于尝试使用dart将图像上传到flutter中的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文