unnecessary_
                  Don't create a lambda when a tear-off will do.
Details
#DON'T create a lambda when a tear-off will do.
BAD:
                    dart
                    
                names.forEach((name) {
  print(name);
});
GOOD:
                    dart
                    
                names.forEach(print);
Enable
#
                  To enable the unnecessary_lambdas rule, add unnecessary_lambdas under
                  linter > rules in your analysis_options.yaml
                   file:
                
analysis_options.yaml
                  
                    yaml
                    
                linter:
  rules:
    - unnecessary_lambdas
                  If you're instead using the YAML map syntax to configure linter rules,
                  add unnecessary_lambdas: true under linter > rules:
                
analysis_options.yaml
                  
                    yaml
                    
                linter:
  rules:
    unnecessary_lambdas: true
Was this page's content helpful?
                      
                    Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Report an issue.