【问题标题】:FAILED ASSERTION : LINE 205 POS 16 :IMAGEURL != NULL IS NOT TRUE断言失败:第 205 行 POS 16:IMAGEURL != NULL 不正确
【发布时间】: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) =&gt; PostScreen( postId: post.postId, userId: post.ownerId, ), ), ); } @override Widget build(BuildContext context) { return GestureDetector( onTap: () =&gt; showPost(context), child: cachedNetworkImage(post.mediaUrl), ); } }
  • 我更新了我的答案,检查一下
  • 这个问题应该改进以对其他人有所帮助。这是关于如何编写好问题How to Ask 以及最小可重现示例minimal reproducible example 的重要性的一个很好的资源。社区成员请使用“flag”/“close”投票来改进这个问题。

标签: android flutter dart


【解决方案1】:

1)。 对于 ImageUrl 检查,

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: imageCheck(post.mediaUrl),
    );
  }

  imageCheck(mediaUrl) {
    var imageUrl=mediaUrl.toString();
    print("image Url :-"+imageUrl);
    if(imageUrl=='null'){
      imageUrl='https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png';
    }
    return cachedNetworkImage(imageUrl);
  }
}

我添加了 imageurl null 的条件,我也在那里打印。 可能对你有帮助。

2).

此代码用于如何加载 .svg 图像。

签出您的 pubspec.yaml 文件,

你是这样添加图片路径的吗,

new SvgPicture.asset(
  'assets/fingerprint.svg',
  height: 20.0,
  width: 20.0,
  allowDrawingOutsideViewBox: true,
),

【讨论】:

  • 是的,我已经在 pubspec.yaml 文件中添加了资产,但它仍然无法正常工作,它在终端中显示错误是由 posttile 引起的。
  • 好的,所以您需要在此处添加 posttile 小部件代码的代码,我知道您在 svg 图像中遇到问题。
  • 更新代码后还是不行。还是同样的错误 imageurl != null is not true
  • 所以,再检查一遍
猜你喜欢
  • 2021-05-04
  • 2020-10-10
  • 2021-05-12
  • 1970-01-01
  • 2021-09-12
  • 2020-04-03
  • 2019-05-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多