Skip to main content

undefined_prefixed_name_write

Details about the 'undefined_prefixed_name_write' diagnostic produced by the Dart analyzer.

The constant '{0}' imported with the prefix '{1}' can't be assigned to.

The name '{0}' is declared in '{1}', but private names are visible only in their own library.

The setter '{0}' isn't defined in the libraries imported with the prefix '{1}'.

The variable '{0}' imported with the prefix '{1}' is final, so it can't be assigned to.

The {0} '{1}' imported with the prefix '{2}' can't be assigned to.

There's a getter '{0}' in the libraries imported with the prefix '{1}', but no setter.

Description

#

The analyzer produces this diagnostic when a name is assigned through an import prefix, but none of the libraries imported with that prefix has a setter or non-final variable with that name.

Examples

#

The following code produces this diagnostic because dart:core doesn't define anything named a:

dart
import 'dart:core' as p;
​
void f() {
  p.a = 0;
}

Given a file a.dart that contains:

dart
int get x => 0;

The following code produces this diagnostic because a.dart has only a getter named x:

dart
import 'a.dart' as p;
​
void f() {
  p.x = 0;
}

The following code produces this diagnostic because pi is a constant:

dart
import 'dart:math' as p;
​
void f() {
  p.pi = 0;
}

Common fixes

#

If the library in which the setter is declared isn't imported yet, then import it with the prefix.

If the name is wrong, then change it to the name of a setter or variable that's declared in the imported libraries.

If the library has only a getter, then add a setter with the same name to that library. If the variable is final, then make it non-final.

Otherwise, remove the assignment.