Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

342
Visualizações
The value of the local variable '***' isn't used. Dart SWITCH statement

I'm new to Dart and I'm hoping someone can explain this variable scoping warning.

When I use the following:

enum fruits {tomatoes, apples, oranges}

void main() {
  
  for (var item in fruits.values) {
    
    var color = 'red';          // Local variable 'color' declared
   
    switch (item){     
      case fruits.apples: 
       break; 
      case fruits.tomatoes:
       break;
      default:
       color = 'orange';        // Local variable 'color' used, analyzer doesn't see
       break;}  
    
    print (color);              // Local variable 'color' used, analyzer sees
    }
}

The code analyzer has no problem with the above. But if I comment out the print statement // print (color);, I get the warning The value of the local variable 'color' isn't used. from the analyzer even though color is used in the default case of the switch statement.

Why doesn't the analyzer "see" the local variable in the default case?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

because assigning the variable colors is not consider using the variable.... for example printing the color consider using the variable. When you use the color for a widget or any thing else then the lint will gone.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda