CancellationToken class

A token that can cancel one or more in-flight/pending requests.

Create one per request (or share across a group), then pass it as cancelToken to any HTTP method. Call cancel to abort all requests that reference this token.

final token = CancellationToken();

final response = await http.get<User>(
  endpoint: '/users/1',
  cancelToken: token,
);

// Elsewhere:
token.cancel();

Constructors

CancellationToken({String? tag})

Properties

hashCode int
The hash code for this object.
no setterinherited
isCancelled bool
Whether this token has been cancelled.
no setter
onCancelled Stream<void>
A stream that emits once when the token is cancelled.
no setter
reason String?
The reason provided when cancel was called.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
tag String?
Optional group tag. Used by FlSmartHttp.cancelGroup.
no setter

Methods

cancel([String reason = 'Request cancelled by caller']) → void
Cancel all requests using this token.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
throwIfCancelled() → void
Throw RequestCancelledException if already cancelled.
toString() String
A string representation of this object.
inherited

Operators

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