Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

337
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda