How to enable 'constructor-tearoffs' feature?
Constructor tearoffs are not going to help you accomplish this. The only approach I'm aware of that could work here is to use a typedef
assigned to Dummy<Int>
and assign t
to that.
class Dummy<T> {
T? value;
}
typedef DummyInt = Dummy<int>;
void main() {
Type t = DummyInt;
}
For anyone who actually does want to enable constructor tearoffs see the documentation on experimental flags. Use the flag constructor-tearoffs
either by passing it in as a command line argument like dart --enable-experiment=constructor-tearoffs bin/your_program.dart
or by configuring it in your analysis_options.yaml
file or Visual Studio Code settings as described in the link.
UPDATE: As of Dart 2.15, constructor tear-offs have been added to the language, and you no longer need to use an experimental flag.
Admin
Updated on December 16, 2022Comments
-
Admin over 1 year
When I try to get the type of a class with generic
class Dummy<T> { T? value; } void main() { Type t = Dummy<int>; }
I get this error:
This requires the 'constructor-tearoffs' language feature to be enabled.
Try updating your pubspec.yaml to set the minimum SDK constraint to 2.14.0 or higher, and running 'pub get'.My pubspec.yaml containes the right SDK version, and I run already flutter clean and flutter pub get
environment: sdk: ">=2.14.4 <3.0.0"
How do I solve it?
-
obe over 2 yearsThis doesn't answer the question... how to enable constructor-tearoffs?
-
mmcdon20 over 2 years@obe I have updated my response with information on how to enable constructor tear-offs.