Home > database >  How to enable 'constructor-tearoffs' feature?
How to enable 'constructor-tearoffs' feature?

Time:11-10

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?

CodePudding user response:

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;
}
  • Related