onBlockTap method
void
onBlockTap(
- int index
)
Implementation
void onBlockTap(int index) async {
setState(() {
tapOrder.add(index);
});
if (tapOrder.length == numberOfBlocks) {
finishedTask = true;
bool wasCorrect = true;
for (int x = 0; x < numberOfBlocks; x++) {
if (tapOrder[x] != blocks[x]) wasCorrect = false;
}
if (!wasCorrect) {
if (failedLast) {
widget.eventLogger.addWrongGesture('Button tap',
'Test Finished after second fail - Tapped the order: $tapOrder. The correct order was: ${blocks.getRange(0, numberOfBlocks)}');
setState(() {
taskInfo = locale?.translate('corsi_block.finished') ?? 'Finished';
});
await Future<dynamic>.delayed(const Duration(milliseconds: 700));
widget.onResultChange(corsiSpan);
widget.eventLogger.testEnded();
if (widget.activity.includeResults) {
widget.eventLogger.resultsShown();
setState(() {
activityStatus = ActivityStatus.Result;
});
}
} else {
widget.eventLogger.addWrongGesture('Button tap',
'Failed first try - Tapped the order: $tapOrder. The correct order was: ${blocks.getRange(0, numberOfBlocks)}');
failedLast = true;
setState(() {
taskInfo =
locale?.translate('corsi_block.try_again') ?? 'Try again';
});
await Future<dynamic>.delayed(const Duration(milliseconds: 700));
startTest();
}
} else {
widget.eventLogger.addCorrectGesture('Button tap',
'Succeeded test in ${!failedLast ? 'first' : 'second'} try. Tap order was: $tapOrder');
setState(() {
failedLast = false;
taskInfo = locale?.translate('corsi_block.well_done') ?? 'Well done!';
});
corsiSpan = numberOfBlocks;
numberOfBlocks++;
await Future<dynamic>.delayed(const Duration(milliseconds: 700));
startTest();
}
}
}