简体   繁体   English

Dart 2.17.0:如何启用“增强枚举”?

[英]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:进入项目中的pubspec.yaml文件,确保sdk的最低版本为2.17.0 ,例如:

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.这样做的原因是 Dart 会跟踪何时引入特性,并确保您的项目不会使用与项目指定的版本范围不兼容的特性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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