tighten_type_of_initializing_formals
Use a type annotation rather than 'assert' to enforce non-nullability.
Description
#The analyzer produces this diagnostic when an assert
is being used in the initializer list of a constructor to ensure that only a non-null
value is being used to initialize a field.
Example
#The following code produces this diagnostic because an assert
is being used to catch an error that could be caught by the type system:
dart
class C {
final String? s;
C(this.s) : assert(s != null);
}
Common fixes
#Remove the assert
and add the non-nullable type before the initializing formal:
dart
class C {
final String? s;
C(String this.s);
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.