copyWith method

MutationState<TData, TVariables, TOnMutateResult> copyWith({
  1. MutationStatus? status,
  2. bool? hasData,
  3. TData? data,
  4. Object? error,
  5. StackTrace? errorStackTrace,
  6. TVariables? variables,
  7. bool? hasVariables,
  8. TOnMutateResult? onMutateResult,
  9. int? failureCount,
  10. Object? failureReason,
  11. bool? isPaused,
  12. DateTime? submittedAt,
  13. bool clearData = false,
  14. bool clearError = false,
  15. bool clearFailureReason = false,
})

A copy with the given fields replaced. null leaves a field as it was; the clear* flags are how a field is set back to nothing.

Implementation

MutationState<TData, TVariables, TOnMutateResult> copyWith({
  MutationStatus? status,
  bool? hasData,
  TData? data,
  Object? error,
  StackTrace? errorStackTrace,
  TVariables? variables,
  bool? hasVariables,
  TOnMutateResult? onMutateResult,
  int? failureCount,
  Object? failureReason,
  bool? isPaused,
  DateTime? submittedAt,
  bool clearData = false,
  bool clearError = false,
  bool clearFailureReason = false,
}) =>
    MutationState<TData, TVariables, TOnMutateResult>(
      status: status ?? this.status,
      hasData: clearData ? false : (hasData ?? this.hasData),
      // `data` and `hasData` travel together, as on `QueryState`: with
      // `hasData: true` the value is authoritative even when it is `null`.
      data: clearData ? null : (hasData == true ? data : (data ?? this.data)),
      error: clearError ? null : (error ?? this.error),
      errorStackTrace:
          clearError ? null : (errorStackTrace ?? this.errorStackTrace),
      variables: variables ?? this.variables,
      hasVariables: hasVariables ?? this.hasVariables,
      onMutateResult: onMutateResult ?? this.onMutateResult,
      failureCount: failureCount ?? this.failureCount,
      failureReason:
          clearFailureReason ? null : (failureReason ?? this.failureReason),
      isPaused: isPaused ?? this.isPaused,
      submittedAt: submittedAt ?? this.submittedAt,
    );