Ephenodrom / Dart-Basic-Utils

A dart package for many helper methods fitting common situations
MIT License
364 stars 77 forks source link

The getter 'name' isn't defined for the class 'Enum'. #64

Closed dzen1984 closed 2 years ago

dzen1984 commented 2 years ago

Cannot build empty flutter project with dependency basic_utils: ^4.0.1

Error: The getter 'name' isn't defined for the class 'Enum'. Try correcting the name to the name of an existing getter, or defining a getter or field named 'name'. : element.name == enumName, ^^^^

The source code from EnumUtils:

static T getEnum<T extends Enum>(
      final String enumName, final List<T> enumList, final T defaultEnum,
      {bool ignoreCase = false}) {
    return enumList.firstWhere(
      (element) => ignoreCase
          ? element.name.toUpperCase() == enumName.toUpperCase()
          : element.name == enumName,
      orElse: () => defaultEnum,
    );
  }  

Indeed, the class Enum does not contain the field "name". Source code for Enum:

@Since("2.14")
abstract class Enum {
  int get index;
}

Have I missed some things?

RicardoRB commented 2 years ago

Hey @dzen1984 the problem is you dart SDK version, in the version 2.15.0 was added "name" to Enum.

Upgrading your dart SDK must fix the error, more info here: https://dart.dev/get-dart#install

The problem is in the "pubspec.yaml" the required SDK is:

environment:
  sdk: '>=2.14.0 <3.0.0'

and it should be:

environment:
  sdk: '>=2.15.0 <3.0.0'

More info: https://github.com/dart-lang/sdk/blob/main/CHANGELOG.md#dartcore-2