use_ late_ for_ private_ fields_ and_ variables
Use 'late' for private members with a non-nullable type.
Description
#
The analyzer produces this diagnostic when a private field or variable is
marked as being nullable, but every reference assumes that the variable is
never
null
.
Example
#
The following code produces this diagnostic because the private top-level
variable
_i
is nullable, but every reference assumes that it will not be
null
:
void f() {
_i!.abs();
}
int? _i;
Common fixes
#
Mark the variable or field as being both non-nullable and
late
to
indicate that it will always be assigned a non-null:
void f() {
_i.abs();
}
late int _i;
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.