简体   繁体   中英

Dart 2.17.0: how do I enable "enhanced-enums"?

Code example:

enum ShareType {
NONE('N'),
PUBLISH('P'),
  SHARE('S');

final String key;
const ShareType(String keyToSet) {this.key = keyToSet;}
}

gives error:

This requires the 'enhanced-enums' language feature to be enabled.

How do I enable this feature? Where must this be set?

Go into your pubspec.yaml file in your project and make sure that the minimum version for the sdk are 2.17.0 like:

environment:
  sdk: ">=2.17.0 <3.0.0"

The reason for this is that Dart keeps track of when features are introduced and makes sure your project does not make use of features that would not be compatible for the range of versions your project have specified as required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM