在我的数据中,我有帖子,但是有些具有图片网址,另一些具有false
值,而在显示时我想显示占位符,其中值是false
这是我的代码:
child: FadeInImage(
placeholder: AssetImage('assets/images/placeholder.png'),
image: NetworkImage(posts[index].featuredImage.large ) == null ?
Image.asset('assets/images/placeholder.png') : NetworkImage(posts[index].featuredImage.large ),
fit: BoxFit.cover,
),
您可以尝试,
child: new Container(
child: FadeInImage.assetNetwork(
placeholder: 'assets/images/placeholder.png',
image:posts[index].featuredImage.large
)
)
以及在pubspec.yaml中]
assets:
- assets/images/placeholder.png
此操作方法