移除 describeEnum
`describeEnum` 方法已從 Flutter framework 中移除。 自 Dart 2.14 起,enum 就有 `name` getter,功能與其相同。
摘要
#
describeEnum 方法已從 framework 中移除,因為它與 Enum 上的 name
getter 功能重複,而該 getter 是在 Dart 2.14 中引入的。
背景
#
過去 Flutter 使用 describeEnum 來回傳 enum 值的 String 描述。
自從 Dart 2.14 引入 Enum 的 name getter 後,這個方法就變得多餘了。
遷移指南
#
如果你的程式碼先前使用 describeEnum 方法來取得 enum 成員的值名稱,
請改為直接使用實例本身的 name getter。
enum Theme { light, dark }
final theme = describeEnum(Theme.light);
Theme.light.name;
時程
#
合併於版本:TBD
穩定版發布:TBD
參考資料
#API 文件:
相關 PR:
Unless stated otherwise, the documentation on this site reflects Flutter 3.47. Page last updated on 2026-10-25. View source or report an issue.