Skip to content

UserTask

A task the user needs to do, e.g. fill in a survey.

It is shown in the app's task list. A user task is the runtime form of an AppTask. It is created by a UserTaskFactory each time the app task is triggered, and put on the AppTaskController queue. The app shows it to the user and calls onStart, onCancel, onDone or onExpired as the user acts on it.

Key points:

Implementers

Constructors

UserTask

UserTask(
  1. AppTaskExecutor<AppTask> executor
)

Creates a user task wrapping executor, with a new id.

Properties

appTaskExecutor

AppTaskExecutor<AppTask> get appTaskExecutor

The AppTaskExecutor this user task wraps.

availableForUser

bool get availableForUser

Whether the user can do this task now.

True if it is enqueued, notified or canceled.

backgroundTaskExecutor

BackgroundTaskExecutor backgroundTaskExecutor
getter/setter pair

Collects the measures of AppTask.backgroundTask once started.

Its measurements are forwarded through appTaskExecutor.

description

String get description

doneTime

DateTime? doneTime
getter/setter pair

The time this task was marked as done in the onDone method.

enqueued

DateTime enqueued
getter/setter pair

The time this task was added to the queue.

expiresIn

Duration? get expiresIn

The time left until this task expires, based on AppTask.expire.

Negative if this task has expired. null if it never expires.

hasNotificationBeenCreated

bool hasNotificationBeenCreated
getter/setter pair

Whether the NotificationManager has created a notification for it.

hasWidget

bool get hasWidget

Whether this task has a widget to show to the user. False by default.

id

String id
getter/setter pair

A unique id of this user task, a v4 UUID.

instructions

String get instructions

name

String get name

notification

bool get notification

Whether a notification should be shown for this task.

result

Data? result
getter/setter pair

The result of this task, set by onDone. Null until then.

state

UserTaskState get state
set state (UserTaskState state)

The state of this task. Setting it emits the new state on stateEvents.

stateEvents

Stream<UserTaskState> get stateEvents

A stream of state changes of this user task.

This stream is useful in a StreamBuilder to listen on changes to a UserTask.

studyDeploymentId

String? get studyDeploymentId

The id of the study deployment this task belongs to.

Null if the executor has no deployment.

task

AppTask get task

The AppTask this user task was created from.

title

String get title

triggerTime

DateTime triggerTime
getter/setter pair

The time this task should trigger (typically becoming visible to the user).

type

String get type

widget

Widget? get widget

The widget to be shown to the user as part of this task, if any. Note that the user interface may not be available before the onStart method has been called.

Methods

onCancel

void onCancel({
  1. bool dequeue = false,
})

Called by the app when the user cancels this task.

If dequeue is true the task is removed from the queue. Otherwise, it is kept on the queue with state UserTaskState.canceled.

onDone

void onDone({
  1. bool dequeue = false,
  2. Data? result,
})

Called by the app when the user has finished this task.

Sets result, doneTime and state, and marks the task as done in the AppTaskController. If dequeue is true the task is also removed from the queue.

onExpired

void onExpired({
  1. bool dequeue = true,
})

Called by the app when this task expires.

If dequeue is true (the default) the task is removed from the queue, which also deletes it from persistent storage. Pass false to keep it on the queue with state UserTaskState.expired, so it still counts in AppTaskController.taskExpired.

onNotification

void onNotification()

Called by the AppTaskController when the user taps the notification.

Does nothing by default; subclasses can override it.

onStart

void onStart()

Called by the app when the user starts this task.

Initializes backgroundTaskExecutor and sets state to UserTaskState.started.

toString

String toString()
override

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.