简体   繁体   中英

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

I'm using the latest version of all these packages.

dependencies
  json_annotation: ^4.5.0

dev_dependencies:
  json_serializable: ^6.2.0
  build_runner: ^2.1.10

I also found that json_serializable: 6.1.5 added support for enhanced enums . But when I run flutter pub build_runner build on

@JsonEnum(fieldRename: FieldRename.snake)
enum Foo {
  helloWorld,
  bar;
}

I get this error:

This builder requires Dart inputs without syntax errors. However, package:example/main.dart (or an existing part) contains the > following errors. main.dart:15:8: This requires the 'enhanced-enums' language feature to be enabled.

I also noticed that all these packages's pubspec.yaml are still not using the Dart SDK 2.17.0 . I manually changed them to 2.17.0 .

The only way that i found to run build-runner without errors was adding --enable-experiment=enhanced-enums to the build_runner command so the complete command should be flutter pub run build_runner build --delete-conflicting-outputs --enable-experiment=enhanced-enums . This is only a temporal fix to be able to run the build_runner without errors

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