TaskHandler class
A controller for a specific background task.
Returned by NativeWorkManager.enqueue to allow tracking progress and completion of a specific task without manually filtering global streams.
Usage
final handler = await NativeWorkManager.enqueue(
taskId: 'download-video',
worker: NativeWorker.httpDownload(url: '...'),
);
// 1. Check if OS accepted the task
if (handler.scheduleResult != ScheduleResult.accepted) {
print('Failed to schedule: ${handler.scheduleResult}');
return;
}
// 2. Listen to progress for THIS task only
handler.progress.listen((p) {
print('Progress: ${p.progress}% (${p.networkSpeedHuman})');
});
// 3. Wait for final result
final event = await handler.result;
if (event.success) {
print('Finished! Result: ${event.resultData}');
}
- Annotations
Constructors
- TaskHandler({required String taskId, required ScheduleResult scheduleResult})
-
const
Properties
-
events
→ Stream<
TaskEvent> -
A stream of lifecycle events for this specific task.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
progress
→ Stream<
TaskProgress> -
A stream of progress updates for this specific task.
no setter
-
result
→ Future<
TaskEvent> -
A future that completes when the task finishes (either success or failure).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scheduleResult → ScheduleResult
-
The result of the scheduling request.
final
- taskId → String
-
The unique ID of the task.
final
Methods
-
cancel(
) → Future< void> - Cancel this task.
-
getStatus(
) → Future< TaskStatus?> - Get the current status of this task.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited