copyWith method
Device
copyWith({
- ResourceType? type,
- String? id,
- String? idV1,
- DeviceProductData? productData,
- DeviceMetadata? metadata,
- List<
Relative> ? services, - String? identifyAction = "",
- bool copyOriginalValues = true,
Returns a copy of this object with its field values replaced by the ones provided to this method.
Since identifyAction
is nullable, it is defaulted to an empty string in
this method. If left as an empty string, its current value in this
Device object will be used. This way, if it is null
, the program will
know that it is intentionally being set to null
.
copyOriginalValues
is true if you want to maintain the original object's
initial values. This is useful if you plan on using this object in a PUT
request.
Implementation
Device copyWith({
ResourceType? type,
String? id,
String? idV1,
DeviceProductData? productData,
DeviceMetadata? metadata,
List<Relative>? services,
String? identifyAction = "",
bool copyOriginalValues = true,
}) {
Device toReturn = Device(
type: copyOriginalValues ? originalType : (type ?? this.type),
id: id ?? this.id,
idV1: idV1 ?? this.idV1,
productData: productData ?? this.productData.copyWith(),
metadata: copyOriginalValues
? _originalMetadata.copyWith(copyOriginalValues: copyOriginalValues)
: (metadata ??
this.metadata.copyWith(copyOriginalValues: copyOriginalValues)),
services: services ??
this
.services
.map((service) =>
service.copyWith(copyOriginalValues: copyOriginalValues))
.toList(),
identifyAction: copyOriginalValues
? _originalIdentifyAction
: (identifyAction == null || identifyAction.isNotEmpty
? identifyAction
: this.identifyAction),
);
if (copyOriginalValues) {
toReturn.type = type ?? this.type;
toReturn.metadata = metadata ??
this.metadata.copyWith(copyOriginalValues: copyOriginalValues);
toReturn.identifyAction =
identifyAction == null || identifyAction.isNotEmpty
? identifyAction
: this.identifyAction;
}
return toReturn;
}