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) -
constfactory
- UploadState.idle()
-
constfactory
- UploadState.networkError()
-
constfactory
- UploadState.processing()
-
constfactory
- UploadState.success(T data)
-
constfactory
- UploadState.uploading(double progress)
-
progressis in the range 0.0 – 1.0constfactory
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 extensionno setter - isFailed → bool
-
Available on UploadState<
T, E> , provided by the UploadStateX extensionno setter - isIdle → bool
-
Available on UploadState<
T, E> , provided by the UploadStateX extensionno setter - isInProgress → bool
-
Available on UploadState<
T, E> , provided by the UploadStateX extensionno setter - isNetworkError → bool
-
Available on UploadState<
T, E> , provided by the UploadStateX extensionno setter - isProcessing → bool
-
Available on UploadState<
T, E> , provided by the UploadStateX extensionno setter - isSuccess → bool
-
Available on UploadState<
T, E> , provided by the UploadStateX extensionno setter - isUploading → bool
-
Available on UploadState<
T, E> , provided by the UploadStateX extensionno 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