【发布时间】:2020-11-16 06:25:34
【问题描述】:
当我运行我的颤振项目时,我不断收到这个错误:
小部件库捕获的异常 'package:cached_network_image/src/cached_image_widget.dart': 失败 断言:第 205 行第 16 行:'imageUrl!= null':不正确。这 相关的导致错误的小部件是 PostTile
我的代码如下所示:
buildProfilePosts() {
if (isLoading) {
return circularProgress();
} else if (posts.isEmpty) {
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SvgPicture.asset('assets/images/no_content.svg', height: 260.0),
Padding(
padding: EdgeInsets.only(top: 20.0),
child: Text(
"No Posts",
style: TextStyle(
color: Colors.redAccent,
fontSize: 40.0,
fontWeight: FontWeight.bold,
),
),
),
],
),
);
} else if (postOrientation == "grid") {
List<GridTile> gridTiles = [];
posts.forEach((post) {
gridTiles.add(GridTile(child: PostTile( post) ));
});
return GridView.count(
crossAxisCount: 3,
childAspectRatio: 1.0,
mainAxisSpacing: 1.5,
crossAxisSpacing: 1.5,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
children: gridTiles,
);
} else if (postOrientation == "list") {
return Column(
children: posts,
);
}
}
帮助我解决此错误。 谢谢!
【问题讨论】:
-
我的帖子磁贴小部件如下所示:
class PostTile extends StatelessWidget { final Post post; PostTile(this.post); showPost(context) { Navigator.push( context, MaterialPageRoute( builder: (context) => PostScreen( postId: post.postId, userId: post.ownerId, ), ), ); } @override Widget build(BuildContext context) { return GestureDetector( onTap: () => showPost(context), child: cachedNetworkImage(post.mediaUrl), ); } } -
我更新了我的答案,检查一下
-
这个问题应该改进以对其他人有所帮助。这是关于如何编写好问题How to Ask 以及最小可重现示例minimal reproducible example 的重要性的一个很好的资源。社区成员请使用“flag”/“close”投票来改进这个问题。