Getting a image provider dirty state when navigating to another page

77 views Asked by At

I am trying to create an action that presses a send message button and sends the user to the chat page with that specific user and I'm having trouble sending the data to the chat page. I got this error:

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

The error pointed to the widget, Chat located in the profile page here:

ProfilePage.dart


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

This is the the onTap function that calls the widget above

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

This is where the error is pointing where the image is getting a null value, on the Chat page:

Chat.dart

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

I added the User model class here just for reference, just incase it was needed.

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();
    }
  }
}

I'm was trying to attempt this functionality but I'm not sure where I'm messing it up, or what I'm missing. I've checked countless other StackOverflow questions to see if I could figure it out, but I'm still having issues.

Any help is appreciated. Please let me know if I've left any helpful details out. Thanks

0

There are 0 answers