TaskRequest class

A single task request in a chain.

Represents one step in a multi-step workflow. Combine multiple TaskRequests using TaskChainBuilder to create complex sequential or parallel workflows.

Basic Usage

final downloadTask = TaskRequest(
  id: 'download-file',
  worker: NativeWorker.httpDownload(
    url: 'https://cdn.example.com/data.zip',
    savePath: '/tmp/data.zip',
  ),
);

final processTask = TaskRequest(
  id: 'process-data',
  worker: DartWorker(callbackId: 'processZipFile'),
);

// Combine into a chain
await NativeWorkManager.beginWith(downloadTask)
    .then(processTask)
    .enqueue();

With Constraints

final uploadTask = TaskRequest(
  id: 'upload-results',
  worker: NativeWorker.httpUpload(
    url: 'https://api.example.com/results',
    filePath: '/tmp/results.json',
  ),
  constraints: Constraints(
    requiresWifi: true,
    requiresCharging: true,
  ),
);

See Also

Data Flow between Tasks

Tasks in a chain can pass data to subsequent tasks using placeholders in their configuration. Use the format {{task_id.output_key}}, where output_key is a key from the result data the previous task's worker reported — not one of its input config keys. NativeWorker.httpDownload, for example, is configured with savePath but reports its result under filePath; check each worker's doc comment for the exact output keys it emits.

A placeholder that is the entire config value (e.g. zipPath: '{{downloader.filePath}}') resolves to the original typed value (String, int, double, bool) from the previous step's output — not a stringified copy. A placeholder embedded inside a larger string (e.g. '/tmp/{{downloader.filePath}}.bak') is interpolated as a string.

await NativeWorkManager.beginWith(
  TaskRequest(
    id: 'downloader',
    worker: NativeWorker.httpDownload(url: '...', savePath: '/tmp/file.zip'),
  ),
)
.then(TaskRequest(
  id: 'processor',
  worker: NativeWorker.fileDecompress(
    zipPath: '{{downloader.filePath}}', // Use output from previous task
    targetDir: '/data/',
  ),
))
.enqueue();
Annotations

Constructors

TaskRequest({required String id, required Worker worker, Constraints constraints = const Constraints()})
const

Properties

constraints → Constraints
Constraints for this task.
final
hashCode → int
The hash code for this object.
no setteroverride
id → String
Unique identifier for this task.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
worker → Worker
Worker configuration.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toMap() → Map<String, dynamic>
Convert to map for platform channel.
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
override