wordPulse method

void wordPulse()

Implementation

void wordPulse() async {
  //control pulsation of words and pause between them
  disableButton = true;
  pulseTimer.cancel();
  //make sure window is mounted and that test is live before setting state.
  if (mounted && activityStatus == ActivityStatus.Test) {
    setState(() {
      cWord = '----';
      wColor = Colors.black;
      backgroundButtons = [
        Colors.white,
        Colors.white,
        Colors.white,
        Colors.white
      ]; //reset feedback
    });
    await Future<dynamic>.delayed(Duration(
        milliseconds:
            widget.activity.delayTime)); //delay before showing next word
    if (mounted && activityStatus == ActivityStatus.Test) {
      setState(() {
        cWordIndex = _random.nextInt(possColorsString.length);
        wColorIndex = _random.nextInt(possColors.length);
        cWord = possColorsString[cWordIndex];
        wColor = possColors[wColorIndex]; //pick word and color for display
      });
    }
    disableButton = false; //make buttons tap-able
  }

  pulseTimer = Timer(Duration(milliseconds: widget.activity.displayTime), () {
    if (activityStatus == ActivityStatus.Test) {
      if (!clicked) {
        //if tap doesnt happen in time, count is a mistake.
        mistakes++;
        totalWords++;
        // totalWords = totalWords + mistakes + correctTaps;
        // totalWords = mistakes + correctTaps;
        String widgetNoTapColor = possColorsString[wColorIndex];
        widget.eventLogger.addWrongGesture('Button tap',
            'No color tapped. The color was $widgetNoTapColor. The word spelled $cWord. Total words passed: $totalWords');
      } else {
        clicked = false;
      }
      wordPulse();
    }
  }); //call wordPulse recursively for periodic timer effect
}