copyWith method

ClassSwitchStatus copyWith({
  1. SwitchState? state,
  2. String? currentClassId,
  3. String? targetClassId,
  4. int? retryCount,
  5. int? errorCode,
  6. String? errorMessage,
  7. bool clearError = false,
})

返回一个修改了部分字段的新实例。

要显式把 errorCode / errorMessage 置回 null,传 clearError: true (否则传 null 参数会被视为"未修改"保留旧值)。

Implementation

ClassSwitchStatus copyWith({
  SwitchState? state,
  String? currentClassId,
  String? targetClassId,
  int? retryCount,
  int? errorCode,
  String? errorMessage,
  bool clearError = false,
}) {
  return ClassSwitchStatus(
    state: state ?? this.state,
    currentClassId: currentClassId ?? this.currentClassId,
    targetClassId: targetClassId ?? this.targetClassId,
    retryCount: retryCount ?? this.retryCount,
    errorCode: clearError ? null : (errorCode ?? this.errorCode),
    errorMessage: clearError ? null : (errorMessage ?? this.errorMessage),
  );
}