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:
- state follows UserTaskState; changes are emitted on stateEvents. Changes made by the controller are also on AppTaskController.userTaskEvents.
- The measures of AppTask.backgroundTask are collected by backgroundTaskExecutor, initialized when onStart is called.
- Subclasses can provide a widget for the task's UI.
- When done, a CompletedAppTask measurement with the result is added to the study's measurements.
- Implementers
Constructors
UserTask
- AppTaskExecutor<
AppTask> executor
Creates a user task wrapping executor, with a new id.
Properties
appTaskExecutor
The AppTaskExecutor this user task wraps.
availableForUser
Whether the user can do this task now.
True if it is enqueued, notified or canceled.
backgroundTaskExecutor
Collects the measures of AppTask.backgroundTask once started.
Its measurements are forwarded through appTaskExecutor.
description
doneTime
The time this task was marked as done in the onDone method.
enqueued
The time this task was added to the queue.
expiresIn
The time left until this task expires, based on AppTask.expire.
Negative if this task has expired. null if it never expires.
hasNotificationBeenCreated
Whether the NotificationManager has created a notification for it.
hasWidget
Whether this task has a widget to show to the user. False by default.
id
A unique id of this user task, a v4 UUID.
instructions
name
notification
Whether a notification should be shown for this task.
result
The result of this task, set by onDone. Null until then.
state
The state of this task. Setting it emits the new state on stateEvents.
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
The id of the study deployment this task belongs to.
Null if the executor has no deployment.
task
The AppTask this user task was created from.
title
triggerTime
The time this task should trigger (typically becoming visible to the user).
type
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
- 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
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
- 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
Called by the AppTaskController when the user taps the notification.
Does nothing by default; subclasses can override it.
onStart
Called by the app when the user starts this task.
Initializes backgroundTaskExecutor and sets state to UserTaskState.started.
toString
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.