Assign an array value and a variable

Asked

Viewed 35 times

0

I need to assign a value of a list within a variable, but I don’t know how to call it inside the function.

void calcula() {

setState(() {
   double tensaoValue = double.tryParse(tensaoController.text);

  double wattsValue = double.tryParse(wattsController.text);
  double distanciaValue = double.tryParse(distanciaController.text);
 

  
 kva = wattsValue * fp;

 correnteValue =  (raiz * tensaoValue* cos)/kva;

  if(correnteValue  <=30){
   resistenciaValue =    //valor lista[0]
   }else if (correnteValue >30 && correnteValue<=40){
   resistenciaValue = ; //lista[1]
   }else if(correnteValue >40 && correnteValue<=55){
   resistenciaValue = ; //lista[2]
  }else if(correnteValue >55 && correnteValue <=70){
   resistenciaValue =;//lista[3]
  }else if(correnteValue >70 && correnteValue <=100){
   resistenciaValue = ; //lista[4]
   }else if (correnteValue >100 && correnteValue <=130){
  resistenciaValue = ;//lista[5]
  }else if(correnteValue >130 && correnteValue<=175){
   resistenciaValue = ;//lista[6]
 }else if (correnteValue >175 && correnteValue <=275){
  resistenciaValue = ;//lista[7]
 }



});}

    void tabela(){
      var lista = new List();
      lista[0]=8.57;
      lista[1]=5.38;
      lista[2]=3.39;
      lista[3]=2.13;
      lista[4]=1.34;
      lista[5]=0.84;
      lista[6]=0.53;
      lista[7]=0.33;
      lista[8]=0.26;

   }

1 answer

0

If I understand correctly, you want to use the var lista within the function void calcula(). I didn’t understand the sense of creating a function called table to put the list inside. An alternative would be to put the list inside the function calcula() or initialize it within the class if it needs to be accessed by other functions.

void calcula() {

final List<double> lista = [8.57, 5.38, 3.39, 2.13, 1.34, 0.84, 0.53, 0.33, 0.26];

setState(() {
   double tensaoValue = double.tryParse(tensaoController.text);

  double wattsValue = double.tryParse(wattsController.text);
  double distanciaValue = double.tryParse(distanciaController.text);
 

  
 kva = wattsValue * fp;

 correnteValue =  (raiz * tensaoValue* cos)/kva;

  if(correnteValue  <=30){
   resistenciaValue =  lista[0];
   }else if (correnteValue >30 && correnteValue<=40){
   resistenciaValue = lista[1];
   }else if(correnteValue >40 && correnteValue<=55){
   resistenciaValue = lista[2];
  }else if(correnteValue >55 && correnteValue <=70){
   resistenciaValue = lista[3];
  }else if(correnteValue >70 && correnteValue <=100){
   resistenciaValue = lista[4];
   }else if (correnteValue >100 && correnteValue <=130){
  resistenciaValue = lista[5];
  }else if(correnteValue >130 && correnteValue<=175){
   resistenciaValue = lista[6];
 }else if (correnteValue >175 && correnteValue <=275){
  resistenciaValue = lista[7];
 }



});}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.