CancelToken class
Token for cancelling model downloads
Similar to Dio's CancelToken pattern. Create a token and pass it to download methods.
Call cancel()
to cancel all operations using this token.
Example:
final token = CancelToken();
// Start download
downloadModelWithProgress(spec, cancelToken: token);
// Cancel from anywhere
token.cancel('User cancelled');
// Check in error handler
catch (e) {
if (CancelToken.isCancel(e)) {
print('Download cancelled');
}
}
Constructors
Properties
- cancelReason → String?
-
The reason for cancellation, if any
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isCancelled → bool
-
Whether this token has been cancelled
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
whenCancelled
→ Future<
void> -
Future that completes when this token is cancelled
no setter
Methods
-
cancel(
[String reason = 'Operation cancelled']) → void - Cancels all operations using this token
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
throwIfCancelled(
) → void - Throws if this token has been cancelled
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited