导航到另一个页面时使图像提供者变脏状态

问题描述

我正在尝试创建一个操作,该操作按下发送消息按钮并将用户与该特定用户一起发送到聊天页面,但是我无法将数据发送到聊天页面。我收到此错误

The following assertion was thrown building Chat(dirty):
'package:cached_network_image/src/image_provider/_image_provider_io.dart': Failed assertion: line 20 pos 16: 'url != null': is not true

错误指向窗口小部件“聊天”,位于此处的个人资料页面

ProfilePage.dart


messageUser(BuildContext context,{String receiverName,receiverId,receiverAvatar}) {
Navigator.push(context,MaterialPageRoute( builder: (context) => 
 Chat( 
   receiverName: receiverName,receiverId: receiverId,receiverAvatar: receiverAvatar
 ))); }

这是调用上面小部件的onTap函数

onTap: () => 
 messageUser(context,receiverName: user.receiverName,receiverId: user.id,receiverAvatar: user.photoUrl
),),

这是错误指向“聊天”页面上图像获取空值的地方:

Chat.dart

CircleAvatar(
              backgroundColor: Colors.grey,backgroundImage: CachednetworkImageProvider(receiverAvatar),

在这里添加了User模型类,仅供参考,以防万一。

import 'package:cloud_firestore/cloud_firestore.dart';

class User {
  final String id;
  final String profileName;
  final String username;
  final String photoUrl;
  final String url;
  final String email;
  final String bio;
  final Timestamp createdAt;
  final String talkingTo;
  final String receiverName;

  User({
    this.id,this.profileName,this.username,this.photoUrl,this.url,this.email,this.bio,this.createdAt,this.talkingTo,this.receiverName,});

  factory User.fromDocument(DocumentSnapshot doc) {
    if (doc != null) {
      return User(
        id: doc.documentID,email: doc['email'] ?? "",username: doc['username'],photoUrl: doc['photoUrl'],url: doc['photoUrl'],profileName: doc['profileName'],bio: doc['bio'],createdAt: doc['createdAt'],talkingTo: doc['talkingTo'],receiverName: doc['receiverName'],);
    } else {
      return new User();
    }
  }
}

我正在尝试尝试此功能,但不确定将其弄乱的地方或缺少的地方。我检查了无数其他StackOverflow问题,以查看是否可以解决问题,但是仍然有问题。

感谢您的帮助。如果我遗漏了任何有用的信息,请告诉我。谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)