Automated IDE Refactoring: Converting Legacy Constructors to Primary Constructors
Using VS Code and Android Studio automated quick-fixes to convert legacy in-body constructors to primary constructors in Dart 3.13.
Published on • October 24, 2026
AI Assistant

Upgrading existing Flutter applications to adopt Dart 3.13 primary constructors can be performed effortlessly thanks to built-in IDE automated refactorings. Both VS Code (with the Dart extension) and Android Studio / IntelliJ IDEA provide quick-fix actions to convert back and forth between legacy in-body constructors and modern primary constructors.
In this walkthrough, we explore how to use these automated refactorings to streamline codebase migration.
IDE Quick-Fix Actions in VS Code & Android Studio
When editing a Dart class, place your cursor over a constructor name or class declaration and press Ctrl+. (VS Code) or Alt+Enter (Android Studio).
The IDE presents two automated refactoring options:
- Convert to primary constructor: Moves parameter declarations up into the class signature header, simplifying field bindings.
- Convert to in-body constructor: Converts a primary constructor back into a traditional constructor body (useful when adding complex multi-step body logic).
+------------------------------------------------------------+
| class OrderItem { |
| final String id; |
| OrderItem(this.id); <--- Cursor [Ctrl+.] |
| } |
+------------------------------------------------------------+
| 💡 Convert to primary constructor |
| 💡 Convert to in-body constructor |
+------------------------------------------------------------+
Before and After Refactoring Demonstration
Legacy In-Body Constructor (Before)
class OrderItem {
final String id;
final String productName;
final double unitPrice;
final int quantity;
OrderItem({
required this.id,
required this.productName,
required this.unitPrice,
this.quantity = 1,
});
double get totalPrice => unitPrice * quantity;
}
Primary Constructor (After Automated Fix)
class OrderItem({
required this.id,
required this.productName,
required this.unitPrice,
this.quantity = 1,
}) {
final String id;
final String productName;
final double unitPrice;
final int quantity;
double get totalPrice => unitPrice * quantity;
}
Batch Refactoring Entire Workspaces
To refactor your entire project in a single command rather than file-by-file in the editor:
# Analyze project diagnostics
dart analyze
# Apply primary constructor refactoring across all packages
dart fix --apply
Conclusion
Automated IDE refactoring tooling makes upgrading Flutter codebases to Dart 3.13 primary constructors fast, safe, and reliable.