You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deprecate describeEnum + type stricter EnumProperty (#9003)
Sequel to #8571 and
flutter/flutter#125016. This is super small, but
broke a test that copied a Flutter file (and was not modified when
Flutter got updated).
---------
Co-authored-by: Shams Zakhour (ignore Sfshaza) <[email protected]>
title: Migration guide for describeEnum and EnumProperty
3
3
description: Removal of describeEnum and how to migrate
4
4
---
5
5
6
6
## Summary
7
7
8
-
The global method `describeEnum` has been deprecated. Existing uses
8
+
The global method `describeEnum` has been deprecated. Previous uses
9
9
of `describeEnum(Enum.something)` should use
10
10
`Enum.something.name` instead.
11
11
12
+
The class EnumProperty was modified to extend `<T extends Enum?>` instead of `<T>`. Existing uses of `EnumProperty<NotAnEnum>` should use `DiagnosticsProperty<NotAnEnum>` instead.
13
+
12
14
## Context
13
15
14
-
Dart 2.17 introduced enhanced enums. With them, Enum became a type
15
-
and all enums got a `name` getter, which made `describeEnum` redundant.
16
+
Dart 2.17 introduced [enhanced enums][], which added `Enum` as a type.
17
+
As a result, all enums got a `name` getter, which made `describeEnum`
18
+
redundant. Before that, enum classes were often analyzed using an
19
+
`EnumProperty`.
16
20
17
21
The `describeEnum` method was used to convert an enum value to a string,
18
22
since `Enum.something.toString()` would produce `Enum.something` instead
19
23
of `something`, which a lot of users wanted. Now, the `name` getter does this.
20
24
25
+
The `describeEnum` function is being deprecated, so the `EnumProperty` class is updated to only accept `Enum` objects.
26
+
21
27
## Description of change
22
28
23
29
Remove `describeEnum`.
24
30
25
31
- Replace `describeEnum(Enum.something)` with `Enum.something.name`.
26
32
33
+
The `EnumProperty` now expects null or an `Enum`;
34
+
you can no longer pass it a non-`Enum` class.
35
+
27
36
## Migration guide
28
37
29
-
If you used `describeEnum(Enum.field)` to access the string value from an
30
-
enum, you can now call `Enum.field.name`.
38
+
If you previously used `describeEnum(Enum.field)` to access the string value from
39
+
an enum, you can now call `Enum.field.name`.
40
+
41
+
If you previously used `EnumProperty<NotAnEnum>`, you can now use the generic `DiagnosticsProperty<NotAnEnum>`.
31
42
32
43
Code before migration:
33
44
34
45
```dart
35
46
enum MyEnum { paper, rock }
36
47
37
48
print(describeEnum(MyEnum.paper)); // output: paper
0 commit comments