avoid-nullable-tostring
preset: recommended
Warns when the toString
method is called on a nullable value.
Calling toString
on a nullable value can result in an unexpected output (e.g. 'null').
Example
❌ Bad:
void fn(String? nullableValue) {
// LINT: Avoid calling 'toString' on nullable targets. Try replacing with the null-aware '?.toString'.
print(nullableValue.toString());
}
✅ Good:
void fn(String? nullableValue) {
print(nullableValue?.toString());
}