copyWith method

SnapState<T> copyWith({
  1. StateStatus? status,
  2. T? data,
  3. SnapError? error,
  4. String? infoMessage,
  5. String? debugName,
  6. SnapState<T>? oldSnapState,
  7. bool? isImmutable,
})

Copy the state

Implementation

SnapState<T> copyWith({
  StateStatus? status,
  T? data,
  SnapError? error,
  String? infoMessage,
  String? debugName,
  SnapState<T>? oldSnapState,
  bool? isImmutable,
}) {
  final s = SnapState<T>._(
    status: status ?? this.status,
    data: isImmutable == true ? data : data ?? this.data,
    snapError: error ??
        (status == null || status == StateStatus.isWaiting
            ? this.snapError
            : null),
    oldSnapState: (status != null || data != null || error != null)
        ? oldSnapState ?? this
        : this.oldSnapState,
    debugName: debugName ?? _debugName,
    toDebugString: _toDebugString,
    infoMessage: infoMessage ?? _infoMessage,
    isImmutable: isImmutable ?? _isImmutable,
  );
  // assert(_infoMessage == kRefreshMessage ||
  //     infoMessage == kRefreshMessage ||
  //     infoMessage == kDisposeMessage ||
  //     _infoMessage == kInitMessage ||
  //     s.status != s.oldSnapState?.status ||
  //     s != s.oldSnapState);
  return s;
}