non_final_field_in_enum
Enums can only declare final fields.
Description
#The analyzer produces this diagnostic when an instance field in an enum isn't marked as final
.
Example
#The following code produces this diagnostic because the field f
isn't a final field:
dart
enum E {
c;
int f = 0;
}
Common fixes
#If the field must be defined for the enum, then mark the field as being final
:
dart
enum E {
c;
final int f = 0;
}
If the field can be removed, then remove it:
dart
enum E {
c
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.