startTest function

void startTest(
  1. BuildContext context
)

This function is called when the trial test is to be started. The only argument is the context so that the function can access the providers. When the function is executed, it navigates to the CountdownScreen, to whom it passes a series of instructions to execute when the countdown finishes. These instructions reset a series of control variables, shuffle the symbols, start the timer and pops the TestScreen.

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 th providers.

Implementation

void startTest(BuildContext context){
  final parametersProvider = Provider.of<ParametersProvider>(context, listen: false);
  final progressProvider = Provider.of<ProgressProvider>(context, listen: false);
  final symbolsProvider = Provider.of<SymbolsProvider>(context, listen: false);
  final timeProvider = Provider.of<TimeProvider>(context, listen: false);
  final personalDataProvider = Provider.of<PersonalDataProvider>(context, listen: false);

    Navigator.pushNamed(context, '/countdownScreen', arguments: (){
      /// So the test screen knows it has to start the timer
      timeProvider.setIsTimeStarted(false);
      /// This functions starts the TRIAL test
      parametersProvider.setIsTrialTest(true);
      progressProvider.resetThirdsCounter();
      parametersProvider.setSaveButtonPressed(false);
      /// Generates the set of symbols the user selected in the profile
      symbolsProvider.setSymbols(personalDataProvider.profilesList[personalDataProvider.activeUser ?? 0].isSymbols1 ?? true);
      /// Generate sequence so all symbols display during trial
      symbolsProvider.generateNewOrder();
      symbolsProvider.resetTrialCounter();
      timeProvider.resetPartialTimes();
      Navigator.pushNamed(context, '/testScreen');
    });
}