testTimer method

void testTimer()

Implementation

void testTimer() {
  //times the test and calculates result when done.
  Timer(Duration(seconds: widget.activity.lengthOfTest), () {
    widget.eventLogger.testEnded();
    widget.eventLogger.resultsShown();
    if (mounted) {
      if (rtList.isEmpty) {
        //if nothing was pressed during the whole test, add 0.
        rtList.add(0);
      }
      for (int i = 0; i < rtList.length; i++) {
        result += (rtList[i]);
      }
      result = (result / rtList.length)
          .round(); //calculate average delay from test.
      widget.onResultChange({
        'avg. reaction time': result,
        'Wrong taps': wrongTaps,
        'Correct taps': correctTaps
      });
      if (widget.activity.includeResults) {
        widget.eventLogger.resultsShown();
      }
      setState(() {
        activityStatus = ActivityStatus.Result;
      });
    }
  });
}