Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

333
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!