iDecode
iDecode

Reputation: 28886

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

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 '}'.

Upvotes: 9

Views: 3908

Answers (2)

Shohin
Shohin

Reputation: 545

Closing and reopening IDEA helped me. In my case the IDEA is VSCode.

Upvotes: -1

iDecode
iDecode

Reputation: 28886

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);
    }
    

Upvotes: 13

Related Questions