copyWith method
Message
copyWith({
- String? id,
- String? text,
- String? type,
- List<
Attachment> ? attachments, - List<
User> ? mentionedUsers, - bool? silent,
- bool? shadowed,
- Map<
String, int> ? reactionCounts, - Map<
String, int> ? reactionScores, - List<
Reaction> ? latestReactions, - List<
Reaction> ? ownReactions, - String? parentId,
- Object? quotedMessage = _nullConst,
- Object? quotedMessageId = _nullConst,
- int? replyCount,
- List<
User> ? threadParticipants, - bool? showInChannel,
- String? command,
- DateTime? createdAt,
- DateTime? localCreatedAt,
- DateTime? updatedAt,
- DateTime? localUpdatedAt,
- DateTime? deletedAt,
- DateTime? localDeletedAt,
- User? user,
- bool? pinned,
- DateTime? pinnedAt,
- Object? pinExpires = _nullConst,
- User? pinnedBy,
- Map<
String, Object?> ? extraData, - MessageState? state,
- Map<
String, String> ? i18n,
Creates a copy of Message with specified attributes overridden.
Implementation
Message copyWith({
String? id,
String? text,
String? type,
List<Attachment>? attachments,
List<User>? mentionedUsers,
bool? silent,
bool? shadowed,
Map<String, int>? reactionCounts,
Map<String, int>? reactionScores,
List<Reaction>? latestReactions,
List<Reaction>? ownReactions,
String? parentId,
Object? quotedMessage = _nullConst,
Object? quotedMessageId = _nullConst,
int? replyCount,
List<User>? threadParticipants,
bool? showInChannel,
String? command,
DateTime? createdAt,
DateTime? localCreatedAt,
DateTime? updatedAt,
DateTime? localUpdatedAt,
DateTime? deletedAt,
DateTime? localDeletedAt,
User? user,
bool? pinned,
DateTime? pinnedAt,
Object? pinExpires = _nullConst,
User? pinnedBy,
Map<String, Object?>? extraData,
MessageState? state,
Map<String, String>? i18n,
}) {
assert(() {
if (pinExpires is! DateTime &&
pinExpires != null &&
pinExpires is! _NullConst) {
throw ArgumentError('`pinExpires` can only be set as DateTime or null');
}
return true;
}(), 'Validate type for pinExpires');
assert(() {
if (quotedMessage is! Message &&
quotedMessage != null &&
quotedMessage is! _NullConst) {
throw ArgumentError(
'`quotedMessage` can only be set as Message or null',
);
}
return true;
}(), 'Validate type for quotedMessage');
assert(() {
if (quotedMessageId is! String &&
quotedMessageId != null &&
quotedMessageId is! _NullConst) {
throw ArgumentError(
'`quotedMessage` can only be set as String or null',
);
}
return true;
}(), 'Validate type for quotedMessage');
return Message(
id: id ?? this.id,
text: text ?? this.text,
type: type ?? this.type,
attachments: attachments ?? this.attachments,
mentionedUsers: mentionedUsers ?? this.mentionedUsers,
silent: silent ?? this.silent,
shadowed: shadowed ?? this.shadowed,
reactionCounts: reactionCounts ?? this.reactionCounts,
reactionScores: reactionScores ?? this.reactionScores,
latestReactions: latestReactions ?? this.latestReactions,
ownReactions: ownReactions ?? this.ownReactions,
parentId: parentId ?? this.parentId,
quotedMessage: quotedMessage == _nullConst
? this.quotedMessage
: quotedMessage as Message?,
quotedMessageId: quotedMessageId == _nullConst
? _quotedMessageId
: quotedMessageId as String?,
replyCount: replyCount ?? this.replyCount,
threadParticipants: threadParticipants ?? this.threadParticipants,
showInChannel: showInChannel ?? this.showInChannel,
command: command ?? this.command,
createdAt: createdAt ?? remoteCreatedAt,
localCreatedAt: localCreatedAt ?? this.localCreatedAt,
updatedAt: updatedAt ?? remoteUpdatedAt,
localUpdatedAt: localUpdatedAt ?? this.localUpdatedAt,
deletedAt: deletedAt ?? remoteDeletedAt,
localDeletedAt: localDeletedAt ?? this.localDeletedAt,
user: user ?? this.user,
pinned: pinned ?? this.pinned,
pinnedAt: pinnedAt ?? this.pinnedAt,
pinExpires:
pinExpires == _nullConst ? this.pinExpires : pinExpires as DateTime?,
pinnedBy: pinnedBy ?? this.pinnedBy,
extraData: extraData ?? this.extraData,
state: state ?? this.state,
i18n: i18n ?? this.i18n,
);
}