copyWith method

GeofenceClient copyWith({
  1. ResourceType? type,
  2. String? id,
  3. String? idV1,
  4. String? name,
  5. Object? isAtHome = sentinelValue,
  6. bool copyOriginalValues = true,
})

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

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

GeofenceClient copyWith({
  ResourceType? type,
  String? id,
  String? idV1,
  String? name,
  Object? isAtHome = sentinelValue,
  bool copyOriginalValues = true,
}) {
  if (!identical(isAtHome, sentinelValue)) {
    assert(isAtHome is bool?, "`isAtHome` must be a `bool?` object");
  }

  GeofenceClient toReturn = GeofenceClient(
    type: copyOriginalValues ? originalType : (type ?? this.type),
    id: id ?? this.id,
    idV1: idV1 ?? this.idV1,
    name: copyOriginalValues ? _originalName : (name ?? this.name),
    isAtHome: copyOriginalValues
        ? _originalIsAtHome
        : (identical(isAtHome, sentinelValue)
            ? this.isAtHome
            : isAtHome as bool?),
  );

  if (copyOriginalValues) {
    toReturn.type = type ?? this.type;
    toReturn.name = name ?? this.name;
    toReturn.isAtHome = identical(isAtHome, sentinelValue)
        ? this.isAtHome
        : isAtHome as bool?;
  }

  return toReturn;
}