finishTrialTest function

void finishTrialTest(
  1. BuildContext context
)

This function is executed when the trial test is finished

First it displays an emerging screen where the user selects which hand the test will be attempted with, giving value to ParametersProvider.hand. Then the following test variables are reset: ProgressProvider.mistakesCounter, ProgressProvider.progressCounter ProgressProvider.thirdsCounter, ProgressProvider.symbolsDisplayed and TimeProvider.partialTimes Then it pushes the CountdownScreen, passing as arguments the functions to execute after the countdown: TimeProvider.setIsTimeStarted, ParametersProvider.setIsTrialTest and pushing the TestScreen

The only argument is the context to access the providers. 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 finishTrialTest(BuildContext context){
  final progressProvider = Provider.of<ProgressProvider>(context, listen:false);
  final parametersProvider = Provider.of<ParametersProvider>(context, listen:false);
  final timeProvider = Provider.of<TimeProvider>(context, listen: false);
  showDialog(
    context: context,
    barrierDismissible: false,
    builder: (context) =>
        AlertDialog(
          title: Text(
            AppLocalizations.of(context)!.well_done,
            style: const TextStyle(
                fontWeight: FontWeight.bold,
                color: AppColors.blueText
            ),
          ),
          content: Text(AppLocalizations.of(
              context)!.trial_completed,
            style: const TextStyle(
                fontSize: 20,
                color: AppColors.blueText
            ),
          ),
          actions: [
            TextButton(
              onPressed: () {
                parametersProvider.setHand('L');
                progressProvider.resetThirdsCounter();
                progressProvider.resetMistakesCounter();
                progressProvider.resetProgressCounter();
                progressProvider.resetSymbolsDisplayed();
                timeProvider.resetPartialTimes();
                parametersProvider.setDataSent(false);
                Navigator.pushNamed(context, '/countdownScreen', arguments: (){
                  timeProvider.setIsTimeStarted(false);
                  parametersProvider.setIsTrialTest(false);
                  Navigator.pushNamed(context, '/testScreen');
                });
              },
              child: Text(AppLocalizations.of(context)!.left,
                  style: TextStyle(
                      fontSize: 20)),
            ),
            TextButton(
              onPressed: () {
                parametersProvider.setHand('R');
                progressProvider.resetThirdsCounter();
                progressProvider.resetMistakesCounter();
                progressProvider.resetProgressCounter();
                progressProvider.resetSymbolsDisplayed();
                timeProvider.resetPartialTimes();
                parametersProvider.setDataSent(false);
                Navigator.pushNamed(context, '/countdownScreen', arguments: (){
                  timeProvider.setIsTimeStarted(false);
                  parametersProvider.setIsTrialTest(false);
                  Navigator.pushNamed(context, '/testScreen');
                });
              },
              child: Text(AppLocalizations.of(context)!.right,
                  style: const TextStyle(
                      fontSize: 20)),
            ),
          ],
        ),
  );
}