codeIdButton function

void codeIdButton(
  1. dynamic context
)

This function is triggered when the button next to the reference code text field is pressed This button is used to edit the code (when in read only mode) or to validate the code (when not in read only mode) using checkCodeid Depending on the result that the check returns, one of the following functions is called: correctCodeId, wrongCodeId, usedCodeId The only argument is context to access the providers

Implementation

void codeIdButton(context) async {
  final parametersProvider = Provider.of<ParametersProvider>(context, listen: false);
  final buttonsProvider = Provider.of<ButtonsProvider>(context, listen: false);

  if(!buttonsProvider.isReadOnly) {
    parametersProvider.setCodeid(
        (parametersProvider.codeidController1.text) + '-' + (parametersProvider.codeidController2.text)
    );
    print(parametersProvider.codeid);
    final int answer = await checkCodeid(
        codeid: parametersProvider.codeid ?? 'c');
    switch (answer) {
      case 2: //Codigo erroneo
        wrongCodeId(buttonsProvider, context);
        break;
      case 3: //Codigo ya utilizado
        usedCodeId(buttonsProvider, context);
        break;
      case 1: //Codigo correcto y no usado
        correctCodeId(buttonsProvider);
        break;
      default:
        buttonsProvider.setIsReadOnly(false);
        break;
    }
  } else{
    buttonsProvider.setIsReadOnly(false);
  }
}