abstract_field_initializer
Abstract fields can't have initializers.
Description
#The analyzer produces this diagnostic when a field that has the abstract
modifier also has an initializer.
Examples
#The following code produces this diagnostic because f
is marked as abstract
and has an initializer:
dart
abstract class C {
abstract int f = 0;
}
The following code produces this diagnostic because f
is marked as abstract
and there's an initializer in the constructor:
dart
abstract class C {
abstract int f;
C() : f = 0;
}
Common fixes
#If the field must be abstract, then remove the initializer:
dart
abstract class C {
abstract int f;
}
If the field isn't required to be abstract, then remove the keyword:
dart
abstract class C {
int f = 0;
}
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.