DeepSource has joined Harness. Learn more
Dart Analyze logoDart Analyze/
DRT-W1234

Invalid setter invocation for final fieldDRT-W1234

Major severityMajor
Bug Risk categoryBug Risk

The analyzer produces this diagnostic when it finds an invocation of a setter, but there's no setter because the field with the same name was declared to be final or const.

Example

The following code produces this diagnostic because v is final:

class C {
  final v = 0;
}

f(C c) {
  c.v = 1;
}

Common fixes

If you need to be able to set the value of the field, then remove the modifier final from the field:

class C {
  int v = 0;
}

f(C c) {
  c.v = 1;
}