我是第一次接触flutter。我从后端获取图像,并使用英雄和FadeInImage在屏幕上显示这些图像。我已经在图像中添加了超链接,并在点击API后生成图像列表。
child: Hero(
tag: tag,
child: FadeInImage(
width: 130.0,
height: 186.0,
placeholder: AssetImage('assets/images/splash1.png'),
fit: BoxFit.cover,
// onTap: _launchUrl(),
image: NetworkImage(
(merchant.logo)),
// fit: BoxFit.cover,
),
),
),
),当我运行我的应用程序时,图像没有加载;屏幕是空的。但当我重新加载时,它显示。
...List.generate(
merchantsList.length,
(index) {
print(merchantsList.length);
print(index);
return MerchantCard(merchant: merchantsList[index]);发布于 2021-05-27 22:39:19
问题是小部件实际上是在列表中填充值之前构建的。我在我的listPopulated函数上使用了setState,它工作得很好。
发布于 2021-05-27 19:54:25
您可以使用占位符图像,也可以添加未来构建器的概念和请检查一次未来的概念。
@override
Widget build(BuildContext context) {
return new FutureBuilder(
future: _loadImage(),
builder: (BuildContext context, AsyncSnapshot<Image> image) {
if (image.hasData) {
return image.data; // image is ready
} else {
return new Container(); // placeholder
}
},
);
}https://stackoverflow.com/questions/67719670
复制相似问题