Activity steps
Build interactive test steps on RPActivityStep, log their timings and gestures, and read the activity result.
An activity step runs an interactive test, such as a reaction time or tapping test, instead of asking a question. Activity steps are subclasses of RPActivityStep that draw the test and report its outcome in an RPActivityResult.
How activity steps work
When an activity step appears, these things happen:
- The step creates an
RPActivityResultwith its identifier, and anRPActivityEventLoggerthat writes into that result. - It calls its
stepBody()with anonResultChangecallback and the logger, and shows the returned widget above the bottom bar. - The test records its stages and the gestures of the participant through the logger.
- The test reports its outcome by calling
onResultChange. Each call stores the value under the keyresult, setsendDateand records the activity result in the task result. - A value that is not
nullenables NEXT, and the participant moves on.
RPActivityStep takes these parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
identifier | String | Yes | — | Identifies the step and its result. |
includeInstructions | bool | No | true | Whether the test shows its own instructions before it starts. |
includeResults | bool | No | true | Whether the test shows its outcome after it ends. |
Research Package does not read includeInstructions and includeResults itself: the subclass decides what they change. The title of an activity step is always RPActivityStep and is not shown. calculateScore() returns 0 unless a subclass overrides it, and Research Package never calls it.
Write an activity step
Extend RPActivityStep and override stepBody() to return the widget of the test. This test counts taps on a button for 10 seconds, logs each tap and reports the count:
The test calls onResultChange once, after the timer. Until then, NEXT stays disabled, so the participant cannot skip the test. Pass a value that JSON can encode, such as a map of numbers and strings: the result stores it as it is.
Use the step in a task like any other step:
To load a task with your own activity step from JSON, add JSON support to the subclass. It needs its own fromJsonFunction getter, a fromJson() factory and a registration in FromJsonFactory from the carp_serializable package.
Without its own fromJsonFunction, the subclass inherits the one of RPActivityStep, and the task loads a plain RPActivityStep that shows an empty screen. For the code, see Add your own step classes.
Event logger
RPActivityEventLogger stamps the current time with each call:
| Method | Records |
|---|---|
instructionStarted(), instructionEnded() | instructionStarted and instructionEnded in stepTimes |
testShown() | testShown: the test is on screen, which may be before it starts |
testStarted(), testEnded() | testStarted and testEnded |
resultsShown(), resultsClosed() | resultsShown and resultsClosed |
addCorrectGesture(type, description) | An Interaction with the correctness Correct gesture |
addWrongGesture(type, description) | An Interaction with the correctness Wrong gesture |
type and description are free text, such as Button tap and the number of the tap.
Read the activity result
The step records an RPActivityResult under its own identifier, tapCount in the example. It has these fields:
| Field | Type | Description |
|---|---|---|
identifier | String | The identifier of the step. |
results | Map<String, dynamic> | The value of the last onResultChange call, under the key result. |
stepTimes | StepTimes | The times the logger recorded. Times that the test never logged stay null. |
interactions | List<Interaction> | The gestures the logger recorded, as Interaction objects with time, correctness, type and description. |
endDate | DateTime? | When the test last reported a result. |
startDate | DateTime? | Not set by activity steps. |
Look up the result by the step identifier, then read the outcome that the test reported:
After three taps, the result of the tapping test is:
In JSON, the keys of stepTimes are in snake case, unset times are left out, and the interactions have no __type. For the dates and for results in general, see Results.
Cognitive tests
cognition_package has 14 cognitive tests built on RPActivityStep, such as the flanker, Stroop and trail making tests. Its version 1.9.1 requires research_package 3.x, so an app that uses it gets research_package 3.2.0. Activity steps and activity results work the same in that version.
For the tests, their parameters and their results, see Cognitive tests.