copyWith method

DevicePower copyWith({
  1. ResourceType? type,
  2. String? id,
  3. String? idV1,
  4. Relative? owner,
  5. DevicePowerPowerState? powerState,
  6. bool copyOriginalValues = true,
})

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

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

DevicePower copyWith({
  ResourceType? type,
  String? id,
  String? idV1,
  Relative? owner,
  DevicePowerPowerState? powerState,
  bool copyOriginalValues = true,
}) {
  DevicePower toReturn = DevicePower(
    type: copyOriginalValues ? originalType : (type ?? this.type),
    id: id ?? this.id,
    idV1: idV1 ?? this.idV1,
    owner:
        owner ?? this.owner.copyWith(copyOriginalValues: copyOriginalValues),
    powerState: powerState ?? this.powerState.copyWith(),
  );

  if (copyOriginalValues) {
    toReturn.type = type ?? this.type;
  }

  return toReturn;
}