checkMatchClick method
void
checkMatchClick(
- int buttonNum
)
Implementation
void checkMatchClick(int buttonNum) async {
//logic for clicking square
if (containers[buttonNum] == matchObject) {
//check if the clicked button matches the object in middle
successes++;
setState(() {
correct = 1; //change icon for feedback - 1 is a tick, 2 is a cross
});
widget.eventLogger.addCorrectGesture('Button tap',
'The tile tapped and match object matched. Level $successes succeeded, by pressing button number $buttonNum.');
await Future<dynamic>.delayed(
const Duration(seconds: 1)); //display feedback
if (successes < levels.length && mounted) {
//as long as there are more levels, go to next.
setState(() {
matchObject = 'packages/cognition_package/assets/images/nothing.png';
containerContent(levels[successes]);
containerPeaker();
});
} else {
//if there are no more levels, end the test.
timer.cancel();
widget.onResultChange(0);
widget.eventLogger.testEnded();
widget.eventLogger.resultsShown();
setState(() {
activityStatus = ActivityStatus
.Result; //if all levels completed within time, end the test.
});
widget.eventLogger.addWrongGesture('Button tap',
'The tile tapped and match object did not match. Level $successes failed, by pressing button number $buttonNum. Retrying level.');
}
} else {
setState(() {
correct = 2; //change icon for feedback - 2 is a cross
});
await Future<dynamic>.delayed(
const Duration(seconds: 1)); //display feedback
//if a mistake has been made, repeat current step.
mistakes++;
if (mounted) {
setState(() {
matchObject = 'packages/cognition_package/assets/images/nothing.png';
containerContent(levels[successes]);
containerPeaker();
});
}
}
}