Skip to main content

external_with_initializer

External fields can't have initializers.

External variables can't have initializers.

Description

#

The analyzer produces this diagnostic when a field or variable marked with the keyword external has an initializer, or when an external field is initialized in a constructor.

Examples

#

The following code produces this diagnostic because the external field x is assigned a value in an initializer:

dart
class C {
  external int x;
  C() : x = 0;
}

The following code produces this diagnostic because the external field x has an initializer:

dart
class C {
  external final int x = 0;
}

The following code produces this diagnostic because the external top level variable x has an initializer:

dart
external final int x = 0;

Common fixes

#

Remove the initializer:

dart
class C {
  external final int x;
}