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

Issue

I just upgraded my Flutter SDK but I am still not able to use the enhanced-enums.

$ dart --version

prints

Dart SDK version: 2.18.0-109.0.dev

This is my code:

enum Foo {
  bar(0),
  baz(1),

  final int i;
  const Foo(this.i);
}

I get the following errors:

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

Expected to find ‘}’.

Solution

There are two problems here.

  1. Update your Dart SDK version constraint in pubspec.yaml file to use the new Dart 2.17.0 version

    environment:
      sdk: ">=2.17.0 <3.0.0"
    

    Then run flutter pub get command

  2. You must end your enum with a semicolon ; and not with a comma ,

    enum Foo {
      bar(0),
      baz(1); // <-- Replaced "," with ";"
    
      final int i;
      const Foo(this.i);
    }
    

Answered By – iDecode

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published