copyWith method

ZigbeeDeviceDiscovery copyWith({
  1. ResourceType? type,
  2. String? id,
  3. String? idV1,
  4. Relative? owner,
  5. String? status,
  6. Object? action = sentinelValue,
  7. bool copyOriginalValues = true,
})

Returns a copy of this object with its field values replaced by the ones provided to this method.

Since action is nullable, it is defaulted to an empty object in this method. If left as an empty object, its current value in this ZigbeeDeviceDiscovery 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

ZigbeeDeviceDiscovery copyWith({
  ResourceType? type,
  String? id,
  String? idV1,
  Relative? owner,
  String? status,
  Object? action = sentinelValue,
  bool copyOriginalValues = true,
}) {
  if (!identical(action, sentinelValue)) {
    assert(action is ZigbeeDeviceDiscoveryAction?,
        "`action` must be a `ZigbeeDeviceDiscoveryAction?` object");
  }

  ZigbeeDeviceDiscovery toReturn = ZigbeeDeviceDiscovery(
    type: copyOriginalValues ? originalType : (type ?? this.type),
    id: id ?? this.id,
    idV1: idV1 ?? this.idV1,
    owner:
        owner ?? this.owner.copyWith(copyOriginalValues: copyOriginalValues),
    status: status ?? this.status,
    action: copyOriginalValues
        ? _originalAction?.copyWith(copyOriginalValues: copyOriginalValues)
        : (identical(action, sentinelValue)
            ? this.action?.copyWith(copyOriginalValues: copyOriginalValues)
            : action as ZigbeeDeviceDiscoveryAction?),
  );

  if (copyOriginalValues) {
    toReturn.type = type ?? this.type;
    toReturn.action = identical(action, sentinelValue)
        ? this.action?.copyWith(copyOriginalValues: copyOriginalValues)
        : action as ZigbeeDeviceDiscoveryAction?;
  }

  return toReturn;
}