[英]API Response image URL not displaying image in flutter
I am trying to show an image which comes from an API response but it's not displaying anything.我正在尝试显示来自 API 响应的图像,但它没有显示任何内容。
I am able to display the image URL, but not the actual image.我能够显示图像 URL,但不能显示实际图像。
Here is my code:这是我的代码:
API call: API调用:
@override
void initState() {
super.initState();
showProgressBar = true;
customFun.readToken().then((val) {
setState(() {
access_token = val;
});
(() async {
await restApis.getProfile(access_token).then((val) => setState((){
print(val);
name = val["data"]["name"];
_nameController.text = val["data"]["name"];
_emailController.text = val["data"]["email"];
_mobileController.text = (val["data"]["contact_number"]).toString();
profile_image = val["data"]["avatarUrl"];
print("-----------------------");
print(profile_image);
print("-----------------------");
showProgressBar = false;
}));
})();
});
}
Here is displaying image code:这是显示图像代码:
(profile_image != '') ?
Container(
width: 150.0,
height: 150.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 1.0,
color: Colors.black
),
image: DecorationImage(
image: NetworkImage("$profile_image"),
fit: BoxFit.fill
),
),
): Container(),
Here is displaying image URL in Text which is working fine:这是在文本中显示图像 URL,它工作正常:
Container(
child: Text("$profile_image")
),
Try adding setState
,尝试添加
setState
,
customFun.readToken().then((val) {
setState(() {
access_token = val;
});
(() async {
await restApis.getProfile(access_token).then((val) => setState((){
print(val);
name = val["data"]["name"];
_nameController.text = val["data"]["name"];
_emailController.text = val["data"]["email"];
_mobileController.text = (val["data"]["contact_number"]).toString();
profile_image = val["data"]["avatarUrl"];
print("-----------------------");
print(profile_image);
print("-----------------------");
showProgressBar = false;
}));
setState((){}); //TODO: ADD THIS
})();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.