Flutter默认图像占位符

问题描述 投票:0回答:2

在我的数据中,我有帖子,但是有些具有图片网址,另一些具有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,
),
flutter dart flutter-layout flutter-dependencies dart-pub
2个回答
0
投票

您可以尝试,

 child: new Container(
      child: FadeInImage.assetNetwork(
          placeholder: 'assets/images/placeholder.png',
          image:posts[index].featuredImage.large
      )
  )

以及在pubspec.yaml中]

assets:
- assets/images/placeholder.png

0
投票

此操作方法

© www.soinside.com 2019 - 2024. All rights reserved.