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:
class C {
external int x;
C() : x = 0;
}
The following code produces this diagnostic because the external field
x
has an initializer:
class C {
external final int x = 0;
}
The following code produces this diagnostic because the external top level
variable
x
has an initializer:
external final int x = 0;
Common fixes
#Remove the initializer:
class C {
external final int x;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.