copyWith method

BehaviorInstance copyWith({
  1. ResourceType? type,
  2. String? id,
  3. String? idV1,
  4. String? scriptId,
  5. bool? isEnabled,
  6. Map<String, dynamic>? state,
  7. Map<String, dynamic>? configuration,
  8. List<BehaviorInstanceDependee>? dependees,
  9. String? status,
  10. String? lastError,
  11. String? name,
  12. String? migratedFrom,
  13. Map<String, dynamic>? trigger = const {},
  14. bool copyOriginalValues = true,
})

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

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

BehaviorInstance copyWith({
  ResourceType? type,
  String? id,
  String? idV1,
  String? scriptId,
  bool? isEnabled,
  Map<String, dynamic>? state,
  Map<String, dynamic>? configuration,
  List<BehaviorInstanceDependee>? dependees,
  String? status,
  String? lastError,
  String? name,
  String? migratedFrom,
  Map<String, dynamic>? trigger = const {},
  bool copyOriginalValues = true,
}) {
  BehaviorInstance toReturn = BehaviorInstance(
    type: copyOriginalValues ? originalType : (type ?? this.type),
    id: id ?? this.id,
    idV1: idV1 ?? this.idV1,
    scriptId:
        copyOriginalValues ? _originalScriptId : (scriptId ?? this.scriptId),
    isEnabled: copyOriginalValues
        ? _originalIsEnabled
        : (isEnabled ?? this.isEnabled),
    state: state ?? Map<String, dynamic>.from(this.state),
    configuration: copyOriginalValues
        ? Map<String, dynamic>.from(_originalConfiguration)
        : (configuration ?? Map<String, dynamic>.from(this.configuration)),
    dependees: dependees ??
        this.dependees.map((dependee) => dependee.copyWith()).toList(),
    status: status ?? this.status,
    lastError: lastError ?? this.lastError,
    name: copyOriginalValues ? _originalName : (name ?? this.name),
    migratedFrom: copyOriginalValues
        ? _originalMigratedFrom
        : (migratedFrom ?? this.migratedFrom),
    trigger: copyOriginalValues
        ? _originalTrigger == null
            ? null
            : Map<String, dynamic>.from(_originalTrigger!)
        : (trigger == null || trigger.isNotEmpty
            ? trigger
            : (this.trigger == null
                ? null
                : Map<String, dynamic>.from(this.trigger!))),
  );

  if (copyOriginalValues) {
    toReturn.type = type ?? this.type;
    toReturn.scriptId = scriptId ?? this.scriptId;
    toReturn.isEnabled = isEnabled ?? this.isEnabled;
    toReturn.configuration =
        configuration ?? Map<String, dynamic>.from(this.configuration);
    toReturn.name = name ?? this.name;
    toReturn.migratedFrom = migratedFrom ?? this.migratedFrom;
    toReturn.trigger = trigger == null || trigger.isNotEmpty
        ? trigger
        : (this.trigger == null
            ? null
            : Map<String, dynamic>.from(this.trigger!));
  }

  return toReturn;
}