copyWith method

Motion copyWith({
  1. ResourceType? type,
  2. String? id,
  3. String? idV1,
  4. Relative? owner,
  5. bool? isEnabled,
  6. bool? hasMotion,
  7. bool? isValidMotion,
  8. 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

Motion copyWith({
  ResourceType? type,
  String? id,
  String? idV1,
  Relative? owner,
  bool? isEnabled,
  bool? hasMotion,
  bool? isValidMotion,
  bool copyOriginalValues = true,
}) {
  Motion toReturn = Motion(
    type: copyOriginalValues ? originalType : (type ?? this.type),
    id: id ?? this.id,
    idV1: idV1 ?? this.idV1,
    owner:
        owner ?? this.owner.copyWith(copyOriginalValues: copyOriginalValues),
    isEnabled: copyOriginalValues
        ? _originalIsEnabled
        : (isEnabled ?? this.isEnabled),
    hasMotion: hasMotion ?? this.hasMotion,
    isValidMotion: isValidMotion ?? this.isValidMotion,
  );

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

  return toReturn;
}