read_
                  The final variable '{0}' can't be read because it's potentially unassigned at this point.
Description
#The analyzer produces this diagnostic when a final local variable that isn't initialized at the declaration site is read at a point where the compiler can't prove that the variable is always initialized before it's referenced.
Example
#
                    The following code produces this diagnostic because the final local
                    variable x is read (on line 3) when it's possible that it hasn't yet
                    been initialized:
                  
int f() {
  final int x;
  return x;
}
Common fixes
#Ensure that the variable has been initialized before it's read:
int f(bool b) {
  final int x;
  if (b) {
    x = 0;
  } else {
    x = 1;
  }
  return x;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-4. View source or report an issue.