copyWith method
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,
- 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,
);
}