【发布时间】:2021-06-11 20:23:28
【问题描述】:
我有上传图片到服务器的功能。但是,小部件在图像上传时开始重建,并且在图像上传后不执行代码。
InkWell(
child: Icon(
Icons.camera,
size: 50,
color: Colors.red[400],
),
onTap: () {
_imageFile =
_picker.getImage(source: ImageSource.camera);
_imageFile.then((file) async {
if (file != null) {
fileName = file.path.toString();
var res = await Auth.uploadImage(file);
print("Response for image upload is : ");
print(res);
await setUserData();
}
});
},
)
这是打印语句在控制台上的输出
I/flutter (10171): Calling build Method
I/Timeline(10171): Timeline: Activity_launch_request time:68831133
I/flutter (10171): Uploading image to server
I/flutter (10171): Calling build Method
I/flutter (10171): Image uploaded successfully
从上面可以看出,没有执行其他代码,并且小部件已自行重建。我可能做错了什么?
【问题讨论】: