Migration guide for describeEnum and EnumProperty

Summary

The global method describeEnum has been deprecated. Previous uses of describeEnum(Enum.something) should use Enum.something.name instead.

The class EnumProperty was modified to extend <T extends Enum?> instead of <T>. Existing uses of EnumProperty<NotAnEnum> should use DiagnosticsProperty<NotAnEnum> instead.

Context

Dart 2.17 introduced enhanced enums, which added Enum as a type. As a result, all enums got a name getter, which made describeEnum redundant. Before that, enum classes were often analyzed using an EnumProperty.

The describeEnum method was used to convert an enum value to a string, since Enum.something.toString() would produce Enum.something instead of something, which a lot of users wanted. Now, the name getter does this.

The describeEnum function is being deprecated, so the EnumProperty class is updated to only accept Enum objects.

Description of change

Remove describeEnum.

  • Replace describeEnum(Enum.something) with Enum.something.name.

The EnumProperty now expects null or an Enum; you can no longer pass it a non-Enum class.

Migration guide

If you previously used describeEnum(Enum.field) to access the string value from an enum, you can now call Enum.field.name.

If you previously used EnumProperty<NotAnEnum>, you can now use the generic DiagnosticsProperty<NotAnEnum>.

Code before migration:

enum MyEnum { paper, rock }

print(describeEnum(MyEnum.paper)); // output: paper

// TextInputType is not an Enum
properties.add(EnumProperty<TextInputType>( ... ));

Code after migration:

enum MyEnum { paper, rock }

print(MyEnum.paper.name); // output: paper

// TextInputType is not an Enum
properties.add(DiagnosticsProperty<TextInputType>( ... ));

Timeline

Landed in version: 3.14.0-2.0.pre
In stable release: 3.16

References

API documentation:

Relevant issues:

Relevant PRs: