testCallback function
- BuildContext context,
- int activeId,
- int activeKey
This function is called every time the test screen widget is reconstructed
Its arguments are context, activeId and activeKey.
First it checks if the test time has been started TimeProvider.isTimeStarted If it has not, it sets the test start time TimeProvider.setStartTime and starts the test timer TimeProvider.startTimer Then calls checkSuccessAndUpdate for the test logic. The providers are instanced with listen:false because the function is outside the widget tree and it does not need to react to changes in the providers.
Implementation
void testCallback(BuildContext context, int activeId, int activeKey){
//Si empezamos el tiempo en countdownScreen, en testScreen sale ya empezado
final progressProvider = Provider.of<ProgressProvider>(context, listen: false);
final parametersProvider = Provider.of<ParametersProvider>(context, listen: false);
final symbolsProvider = Provider.of<SymbolsProvider>(context, listen: false);
final timeProvider = Provider.of<TimeProvider>(context, listen: false);
if (timeProvider.isTimeStarted == false) {
timeProvider.setIsTimeStarted(true);
symbolsProvider.setShuffled(false);
if (parametersProvider.isTrialTest) {
context.read<TimeProvider>().setStartTime();
context.read<TimeProvider>().startTimer(
timeLimit: GeneralConstants.trialDuration,
onFinish: () => finishTrialTest(context),
pp: progressProvider);
}
else if (parametersProvider.isTrialTest == false) {
context.read<TimeProvider>().setStartTime();
context.read<TimeProvider>().startTimer(
timeLimit: GeneralConstants.testDuration,
onFinish: () => finishTest(context),
pp: progressProvider);
}
}
checkSuccessAndUpdate(context, activeId, activeKey);
}