null_ argument_ to_ non_ null_ type
'{0}' shouldn't be called with a 'null' argument for the non-nullable type argument '{1}'.
Description
#
The analyzer produces this diagnostic when
null
is passed to either the
constructor
Future.value
or the method
Completer.complete
when the type
argument used to create the instance was non-nullable. Even though the type
system can't express this restriction, passing in a
null
results in a
runtime exception.
Example
#
The following code produces this diagnostic because
null
is being passed
to the constructor
Future.value
even though the type argument is the
non-nullable type
String
:
Future<String> f() {
return Future.value(null);
}
Common fixes
#Pass in a non-null value:
Future<String> f() {
return Future.value('');
}
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.