TL;DR
Dart 3.13 adds primary constructors – a compact syntax that declares constructor parameters and instance variables directly in the class header. It also adds shorter `new` and `factory` constructor declarations inside class bodies.
Prerequisites
- Dart 3.13 or newer.
- Flutter 3.47 includes Dart 3.13.
- Platforms – Android, iOS, web, Windows, macOS, Linux, and server-side Dart.
1. Replace Constructor Boilerplate
Before Dart 3.13, a small data class often repeated field names several times.
class Point {
final int x;
final int y;
Point(this.x, this.y);
}
With a primary constructor, the fields and constructor can be declared in the class header.
class Point(final int x, final int y);
For mutable fields, use `var`.
class Point(var int x, var int y);
The change is syntactic – primary constructors reduce boilerplate without changing the runtime behavior of object construction.
2. Add Class Members Normally
A class with a primary constructor can still contain methods and other members.
class Point(final int x, final int y) {
int get distanceSquared => x * x + y * y;
}
void main() {
final point = Point(3, 4);
print(point.distanceSquared);
}
Primary constructors are most useful when the constructor parameters closely match the state the object needs to store.
3. Use Concise Constructor Syntax
Dart 3.13 also lets constructors declared inside the class body use `new` instead of repeating the class name.
class Point {
double x;
double y;
new(this.x, this.y);
new origin() : x = 0, y = 0;
}
A concise named constructor does not put a dot between `new` and the constructor name.
4. Shorten Factory Constructors
Factory constructors can also omit the class name.
class Point {
double x;
double y;
new(this.x, this.y);
factory clone(Point other) => Point(other.x, other.y);
}
This makes class renames easier because constructor declarations no longer repeat the old class name throughout the file.
Verify It Works
Check your Dart version first.
dart --version
Then run a Dart 3.13 file containing a primary constructor.
dart run main.dart
If the analyzer reports syntax errors around the class header, confirm that the package SDK constraint and installed Dart SDK both allow Dart 3.13.
When to Use Primary Constructors
Use them for small value objects, configuration objects, coordinates, DTO-style classes, and other types where constructor parameters map directly to stored state.
Keep a traditional or concise body constructor when initialization requires substantial validation, branching, redirection, or setup logic. Shorter syntax should make a class easier to scan – not hide important construction behavior.
Performance & Pitfalls
- Primary constructors are a syntax feature – do not expect runtime performance gains.
- Use `final` when fields should not change after construction.
- Keep complex initialization explicit when that improves readability.
- Packages using the syntax need an SDK constraint that allows Dart 3.13.
References
Related FlutterWire Posts
Tested Versions
Tested with Flutter 3.47 stable and Dart 3.13.

Leave a Reply