copyWith method

Contact copyWith({
  1. String? id,
  2. String? displayName,
  3. Photo? photo,
  4. Name? name,
  5. List<Phone>? phones,
  6. List<Email>? emails,
  7. List<Address>? addresses,
  8. List<Organization>? organizations,
  9. List<Website>? websites,
  10. List<SocialMedia>? socialMedias,
  11. List<Event>? events,
  12. List<Relation>? relations,
  13. List<Note>? notes,
  14. AndroidData? android,
  15. ContactMetadata? metadata,
  16. bool clearPhoto = false,
})

Implementation

Contact copyWith({
  String? id,
  String? displayName,
  Photo? photo,
  Name? name,
  List<Phone>? phones,
  List<Email>? emails,
  List<Address>? addresses,
  List<Organization>? organizations,
  List<Website>? websites,
  List<SocialMedia>? socialMedias,
  List<Event>? events,
  List<Relation>? relations,
  List<Note>? notes,
  AndroidData? android,
  ContactMetadata? metadata,
  // Set to true to explicitly clear the photo (set it to null)
  bool clearPhoto = false,
}) {
  // Handle explicit photo clearing: if clearPhoto is true, set photo to null
  // Otherwise, if photo is provided (not null), use it; else keep existing photo
  final Photo? finalPhoto = clearPhoto ? null : (photo ?? this.photo);

  return Contact(
    id: id ?? this.id,
    displayName: displayName ?? this.displayName,
    photo: finalPhoto,
    name: name ?? this.name,
    phones: phones ?? this.phones,
    emails: emails ?? this.emails,
    addresses: addresses ?? this.addresses,
    organizations: organizations ?? this.organizations,
    websites: websites ?? this.websites,
    socialMedias: socialMedias ?? this.socialMedias,
    events: events ?? this.events,
    relations: relations ?? this.relations,
    notes: notes ?? this.notes,
    android: android ?? this.android,
    metadata: metadata ?? this.metadata,
  );
}