inference_ failure_ on_ uninitialized_ variable
The type of {0} can't be inferred without either a type or initializer.
Description
#The analyzer produces this diagnostic when
- the language option
strict-inference
has been enabled in the analysis options file, - the declaration of a variable doesn't have a type, and
- the type of the variable can't be inferred.
Example
#Given an analysis options file containing the following:
analyzer:
language:
strict-inference: true
The following code produces this diagnostic because the variable
s
doesn't have an explicit type and the type can't be inferred because
there's no initializer:
var s;
Common fixes
#Add an explicit type:
String? s;
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.