Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteCan you use constructor tear-offs with Dart enhanced enums? Not with a generative enum constructor: Dart only permits it to initialize declared enum values or redirect within the same enum. Use a factory constructor when you need a function-like enum API; it can return an existing value, but it cannot create a new one.
What constructor tear-offs do—and why enums differ
A constructor tear-off is a constructor reference used as a function value. For an ordinary class, you can pass StringBuffer.new where a compatible callback is expected instead of writing a forwarding lambda such as (text) => StringBuffer(text). As the Dart constructors guide puts it, “Lambdas serve as a wrapper for the constructor, whereas a tear-off is the constructor.” Dart constructors guide.
As an Amazon Associate I earn from qualifying purchases.
An enhanced enum can have fields, methods and constructors, but its instances are the finite set of values declared in the enum. A generative constructor initializes those declared values; it is not a general-purpose way to create more enum objects. Consequently, MyEnum.new is not a valid callback reference to a generative enum constructor.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Why the analyzer rejects a generative enum constructor reference
The restriction is explicit in Dart’s analyzer diagnostic: “Generative enum constructors can’t be torn off.” A generative enum constructor may be used to initialize one of that enum’s declared values or for a same-enum redirect, not as an independent function reference. See the analyzer diagnostic and the enhanced-enum specification.
#1 Best Overall
For example, in this conventional enhanced-enum declaration, const Mode(1) initializes a declared value; it does not expose Mode.new as a callback:
enum Mode {
compact(1),
expanded(2);
final int scale;
const Mode(this.scale);
}
Enhanced enums require language version 2.17 or later. Their instance variables must be final, and generative constructors must be constant. The Dart enum documentation describes those constraints.
Rank #2
Use a factory when a callback should select an existing enum value
A factory constructor can provide constructor-shaped invocation syntax while returning one of the enum’s already declared values. The analyzer documentation gives this minimal example:
enum E {
a(0);
const E(int x);
factory E.c(int x) => a;
}
E.c is a factory path, not a tear-off of the generative constructor. It returns a, which already exists. In this minimal example the argument does not affect the result; a real factory should use its input for a meaningful mapping where appropriate. It still cannot add enum instances. The distinction and permitted uses are set out in the diagnostic documentation.
Rank #3
For application code, choose the expression that matches the job:
- The desired value is already known: pass the enum constant itself, such as
Mode.compact. - A callback receives input and should map it to a declared value: provide a factory constructor and pass that factory reference if its signature fits the callback type.
- You need to construct arbitrary new objects from callback input: use an ordinary class constructor tear-off, not an enum generative constructor.
A factory does not change the enum’s closed set. It only provides a route to return a member of that set.
Rank #4
Dart 3.13 primary constructors change syntax, not enum construction
The Dart language documentation reflects Dart 3.13.3, and primary constructors offer a shorter declaration style for enhanced enums. For example, the documented primary-constructor form can put a declaring parameter in the enum header:
Free tools Windows power users keep installed
One-click scans. No signup required.
enum Color(int value) {
red(0),
green(1),
blue(2);
final int value;
}
Primary constructors are implicitly constant for enums. This syntax changes how the declaration is written, not the fixed-instance rule or the restriction on tearing off a generative enum constructor. See Dart primary constructors and the enum documentation. Use this newer syntax only when the project’s Dart language version supports it; the traditional enhanced-enum form remains available from language version 2.17.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




