Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Dart 3.3: Why extension types not working?

I am trying to use new feature in dart 3.3 – Extension types. Simple example from doc:

extension type IdNumber(int id) {
  // Wraps the 'int' type's '<' operator:
  operator <(IdNumber other) => id < other.id;
  // Doesn't declare the '+' operator, for example,
  // because addition does not make sense for ID numbers.
}

but in the word type there is an arror:

This requires the 'inline-class' language feature to be enabled.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My flutter version:

Flutter 3.19.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision bae5e49bc2 (6 days ago) • 2024-02-13 17:46:18 -0800
Engine • revision 04817c99c9
Tools • Dart 3.3.0 • DevTools 2.31.1

I was trying to add in pubspec.yaml:

analyzer:
  enable-experiment:
    - inline-class

Not working. Thanks in advance for the tips.

>Solution :

The full error message actually tells you what to do

enter image description here

This requires the ‘inline-class’ language feature to be enabled.
Try updating your pubspec.yaml to set the minimum SDK constraint to 3.3.0 or higher, and running ‘pub get’.

So, if you maybe have this in your pubspec.yaml

sdk: ">=3.0.0 <4.0.0"

change it to

sdk: ">=3.3.0 <4.0.0"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading