UploadState<T, E> class sealed

Represents the state of a file / multipart upload.

States:

  • idle: No upload started
  • uploading: Bytes being sent; progress is 0.0 – 1.0
  • processing: All bytes sent, waiting for server response
  • success: Upload complete, server returned data
  • failed: Upload or server error
  • networkError: Connectivity failure

Example:

UploadState<Photo, ApiError> state = UploadState.idle();

ApiExecutor.uploadStream<Photo, ApiError>(
  request: (onSendProgress) => dio.post(
    '/photos',
    data: formData,
    onSendProgress: onSendProgress,
  ),
  parser: Photo.fromJson,
).listen((state) {
  state.when(
    idle:         ()         => {},
    uploading:    (progress) => updateProgressBar(progress),
    processing:   ()         => showSpinner(),
    success:      (photo)    => showPhoto(photo),
    failed:       (error)    => showError(error.message),
    networkError: ()         => showNoInternet(),
  );
});
Implementers
Available extensions

Constructors

UploadState.failed(FailureResponse<E> error)
const
factory
UploadState.idle()
const
factory
UploadState.networkError()
const
factory
UploadState.processing()
const
factory
UploadState.success(T data)
const
factory
UploadState.uploading(double progress)
progress is in the range 0.0 – 1.0
const
factory

Properties

data → T?
Success data, or null
no setter
error FailureResponse<E>?
Error payload, or null
no setter
hashCode int
The hash code for this object.
no setterinherited
isError bool

Available on UploadState<T, E>, provided by the UploadStateX extension

no setter
isFailed bool

Available on UploadState<T, E>, provided by the UploadStateX extension

no setter
isIdle bool

Available on UploadState<T, E>, provided by the UploadStateX extension

no setter
isInProgress bool

Available on UploadState<T, E>, provided by the UploadStateX extension

no setter
isNetworkError bool

Available on UploadState<T, E>, provided by the UploadStateX extension

no setter
isProcessing bool

Available on UploadState<T, E>, provided by the UploadStateX extension

no setter
isSuccess bool

Available on UploadState<T, E>, provided by the UploadStateX extension

no setter
isUploading bool

Available on UploadState<T, E>, provided by the UploadStateX extension

no setter
progress double?
Progress in 0.0 – 1.0 when uploading, null otherwise
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

maybeWhen<R>({R idle()?, R uploading(double progress)?, R processing()?, R success(T data)?, R failed(FailureResponse<E> error)?, R networkError()?, required R orElse()}) → R
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
when<R>({required R idle(), required R uploading(double progress), required R processing(), required R success(T data), required R failed(FailureResponse<E> error), required R networkError()}) → R

Operators

operator ==(Object other) bool
The equality operator.
inherited