copyWith method

Geolocation copyWith({
  1. ResourceType? type,
  2. String? id,
  3. String? idV1,
  4. bool? isConfigured,
  5. double? latitude,
  6. double? longitude,
  7. 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 Geolocation 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

Geolocation copyWith({
  ResourceType? type,
  String? id,
  String? idV1,
  bool? isConfigured,
  double? latitude,
  double? longitude,
  bool copyOriginalValues = true,
}) {
  Geolocation toReturn = Geolocation(
    type: copyOriginalValues ? originalType : (type ?? this.type),
    id: id ?? this.id,
    idV1: idV1 ?? this.idV1,
    isConfigured: isConfigured ?? this.isConfigured,
    latitude:
        copyOriginalValues ? _originalLatitude : (latitude ?? this.latitude),
    longitude: copyOriginalValues
        ? _originalLongitude
        : (longitude ?? this.longitude),
  );

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

  return toReturn;
}