Skip to content

Commit 6faccb4

Browse files
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]>
1 parent 92f80a5 commit 6faccb4

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed
Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,54 @@
11
---
2-
title: Migration guide for describeEnum
2+
title: Migration guide for describeEnum and EnumProperty
33
description: Removal of describeEnum and how to migrate
44
---
55

66
## Summary
77

8-
The global method `describeEnum` has been deprecated. Existing uses
8+
The global method `describeEnum` has been deprecated. Previous uses
99
of `describeEnum(Enum.something)` should use
1010
`Enum.something.name` instead.
1111

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+
1214
## Context
1315

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`.
1620

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

25+
The `describeEnum` function is being deprecated, so the `EnumProperty` class is updated to only accept `Enum` objects.
26+
2127
## Description of change
2228

2329
Remove `describeEnum`.
2430

2531
- Replace `describeEnum(Enum.something)` with `Enum.something.name`.
2632

33+
The `EnumProperty` now expects null or an `Enum`;
34+
you can no longer pass it a non-`Enum` class.
35+
2736
## Migration guide
2837

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>`.
3142

3243
Code before migration:
3344

3445
```dart
3546
enum MyEnum { paper, rock }
3647
3748
print(describeEnum(MyEnum.paper)); // output: paper
49+
50+
// TextInputType is not an Enum
51+
properties.add(EnumProperty<TextInputType>( ... ));
3852
```
3953

4054
Code after migration:
@@ -43,6 +57,9 @@ Code after migration:
4357
enum MyEnum { paper, rock }
4458
4559
print(MyEnum.paper.name); // output: paper
60+
61+
// TextInputType is not an Enum
62+
properties.add(DiagnosticsProperty<TextInputType>( ... ));
4663
```
4764

4865
## Timeline
@@ -56,21 +73,31 @@ API documentation:
5673

5774
* [`describeEnum` stable][]
5875
* [`describeEnum` main][]
76+
* [`EnumProperty` stable][]
77+
* [`EnumProperty` main][]
78+
* [enhanced enums]: https://github.com/dart-lang/language/blob/main/working/0158%20-%20Enhanced%20Enum/proposal.md
5979

6080
Relevant issues:
6181

62-
* [☂️ Cleanup SemanticsFlag and SemanticsAction issue][]
82+
* [Cleanup SemanticsFlag and SemanticsAction issue][]
6383

6484
Relevant PRs:
6585

6686
* [Deprecate `describeEnum` PR][]
6787

6888
[`describeEnum` stable]: {{site.api}}/flutter/lib/src/foundation/describeEnum.html
6989

90+
[`EnumProperty` stable]: {{site.api}}/flutter/lib/src/foundation/EnumProperty.html
91+
7092
<!-- Master channel link: -->
7193
{% include docs/master-api.md %}
7294

7395
[`describeEnum` main]: {{site.master-api}}/flutter/lib/src/foundation/describeEnum.html
7496

75-
[☂️ Cleanup SemanticsFlag and SemanticsAction issue]: {{site.repo.flutter}}/issues/123346
97+
[`EnumProperty` main]: {{site.master-api}}/flutter/lib/src/foundation/describeEnum.html
98+
99+
[Cleanup SemanticsFlag and SemanticsAction issue][cleanup-issue]
100+
101+
[cleanup-issue]: {{site.repo.flutter}}/issues/123346
102+
76103
[Deprecate `describeEnum` PR]: {{site.repo.flutter}}/pull/125016

src/release/breaking-changes/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ release, and listed in alphabetical order:
3939
* [Customize tabs alignment using the new `TabBar.tabAlignment` property][]
4040
* [Updated EditableText scroll into view behavior][]
4141
* [Deprecate `textScaleFactor` in favor of `TextScaler`][]
42+
* [Deprecate describeEnum and update EnumProperty to be type strict][]
4243

4344
[Added AppLifecycleState.hidden]: {{site.url}}/release/breaking-changes/add-applifecyclestate-hidden
4445
[Deprecated API removed after v3.10]: {{site.url}}/release/breaking-changes/3-10-deprecations
@@ -48,6 +49,7 @@ release, and listed in alphabetical order:
4849
[Customize tabs alignment using the new `TabBar.tabAlignment` property]: {{site.url}}/release/breaking-changes/tab-alignment
4950
[Updated EditableText scroll into view behavior]: {{site.url}}/release/breaking-changes/editable-text-scroll-into-view
5051
[Deprecate `textScaleFactor` in favor of `TextScaler`]: {{site.url}}/release/breaking-changes/deprecate-textscalefactor
52+
[Deprecate describeEnum and update EnumProperty to be type strict]: {{site.url}}/release/breaking-changes/describe-enum
5153

5254
### Released in Flutter 3.10
5355

0 commit comments

Comments
 (0)