Dart Analyze logoDart Analyze/
DRT-W1215

Abstract fields can't have initializersDRT-W1215

Major severityMajor
Bug Risk categoryBug Risk

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:

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:

abstract class C {
  abstract int f;

  C() : f = 0;
}

Common fixes

If the field must be abstract, then remove the initializer:

abstract class C {
  abstract int f;
}

If the field isn't required to be abstract, then remove the keyword:

abstract class C {
  int f = 0;
}