Cleaning Up Dart Codebases: The unnecessary_primary_constructor_body Lint
Eliminating empty {} body blocks in primary constructors when field initializations happen directly in the header signature.
Published on • October 24, 2026
AI Assistant

In Dart 3.13, primary constructors allow parameter signatures to sit directly in the class header. When all fields are initialized via the class header signature and no additional body execution logic is required, adding an empty body block {} is unnecessary verbosity.
The unnecessary_primary_constructor_body lint rule ensures that class declarations remain clean and free of redundant empty bodies.
Code Example: Before and After Cleanup
Non-Idiomatic (Triggers LINT)
Writing an empty curly brace body {} after a primary constructor header signature is redundant:
// LINT: unnecessary_primary_constructor_body triggers here
class AppConfig(this.apiUrl, this.timeoutSeconds) {
final String apiUrl;
final int timeoutSeconds;
}
If the class contains no additional methods or fields beyond what is declared in the header, or if fields are declared directly in the signature, the trailing body block can be omitted or cleaned up:
Idiomatic Dart 3.13
// Clean Dart 3.13 declaration
class AppConfig(this.apiUrl, this.timeoutSeconds) {
final String apiUrl;
final int timeoutSeconds;
}
When using factory redirects or extension types, semicolon termination or bodyless declarations keep the syntax concise:
// Bodyless factory redirect using primary constructors
class Point(this.x, this.y) {
final double x;
final double y;
factory Point.zero() = Point(0.0, 0.0);
}
Linter Configuration
Add unnecessary_primary_constructor_body to your analysis_options.yaml:
linter:
rules:
- unnecessary_primary_constructor_body
Running dart fix --apply automatically removes empty constructor body blocks throughout your project.
Summary
By pairing unnecessary_primary_constructor_body with use_declaring_parameters, Dart developers eliminate unnecessary syntax noise and maintain clean, readable codebases.