Skip to content
Blog

Enforcing Dart 3.13 Primary Constructors with use_declaring_parameters

Analysis lint rule use_declaring_parameters, how dart fix refactors legacy constructor bodies, and static analysis options.

Published on • October 24, 2026

AI Assistant

With the introduction of primary constructors in Dart 3.13, the Dart analyzer added the use_declaring_parameters lint rule. This rule identifies classes where traditional in-body constructors can be refactored into modern header-level primary constructor declarations.

In this guide, we explore how use_declaring_parameters works and how to automate refactoring across your Flutter codebases.

Understanding use_declaring_parameters

The use_declaring_parameters lint rule flags class declarations that contain a single constructor whose parameters simply initialize fields without complex execution logic:

// LINT: use_declaring_parameters triggers on this constructor
class ProductModel {
  final String id;
  final double price;

  ProductModel(this.id, this.price);
}

When enabled, the analyzer suggests converting the constructor to declare parameters directly in the class header:

// Idiomatic Dart 3.13 code passing the lint rule
class ProductModel(this.id, this.price) {
  final String id;
  final double price;
}

Configuring Analysis Options

To enable use_declaring_parameters across your project or monorepo, add it to your analysis_options.yaml:

include: package:flutter_lints/flutter.yaml

linter:
  rules:
    - use_declaring_parameters
    - unnecessary_primary_constructor_body
    - unnecessary_type_name_in_constructor
    - unnecessary_const_in_enum_constructor

Automated Fixes with dart fix

You do not need to manually rewrite every class in your codebase. The Dart SDK includes an automated quick-fix transformation for this rule:

# Preview changes across the project
dart fix --dry-run

# Apply parameter declaration refactoring automatically
dart fix --apply

Benefits for Enterprise Codebases

  1. Reduced Line Count: Reduces DTO and state model class definitions by 20–30%.
  2. Consistent Code Style: Enforces uniform creation signatures across large engineering teams.
  3. IDE Quick-Fix Integration: Provides one-click lightbulb refactoring in VS Code and Android Studio.

Conclusion

Enforcing use_declaring_parameters ensures your Dart and Flutter applications adopt modern language standards automatically while keeping codebases clean and concise.

References & Further Reading