copyWith method

Bridge copyWith({
  1. ResourceType? type,
  2. String? id,
  3. String? idV1,
  4. String? applicationKey = "",
  5. String? ipAddress = "",
  6. Relative? owner,
  7. String? bridgeId,
  8. String? timeZone,
  9. bool copyOriginalValues = true,
})

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

Since ipAddress and applicationKey are nullable, they are defaulted to empty strings in this method. If left as empty strings, their current values in this Bridge object will be used. This way, if they are null, the program will know that they are 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.

Throws InvalidIdException if owner.id is empty and optimizeFor is not set to OptimizeFor.dontOptimize.

Implementation

Bridge copyWith({
  ResourceType? type,
  String? id,
  String? idV1,
  String? applicationKey = "",
  String? ipAddress = "",
  Relative? owner,
  String? bridgeId,
  String? timeZone,
  bool copyOriginalValues = true,
}) {
  Bridge toReturn = Bridge(
    type: copyOriginalValues ? originalType : (type ?? this.type),
    id: id ?? this.id,
    idV1: idV1 ?? this.idV1,
    applicationKey: applicationKey == null || applicationKey.isNotEmpty
        ? applicationKey
        : this.applicationKey,
    ipAddress: ipAddress == null || ipAddress.isNotEmpty
        ? ipAddress
        : this.ipAddress,
    owner:
        owner ?? this.owner.copyWith(copyOriginalValues: copyOriginalValues),
    bridgeId: bridgeId ?? this.bridgeId,
    timeZone: timeZone ?? this.timeZone,
  );

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

  return toReturn;
}