unnecessary_null_in_if_null_operators
Unnecessary use of '??' with 'null'.
Description
#The analyzer produces this diagnostic when the right operand of the ??
operator is the literal null
.
Example
#The following code produces this diagnostic because the right-hand operand
of the ??
operator is null
:
dart
String? f(String? s) => s ?? null;
Common fixes
#If a non-null value should be used for the right-hand operand, then change the right-hand side:
dart
String f(String? s) => s ?? '';
If there is no non-null value to use for the right-hand operand, then remove the operator and the right-hand operand:
dart
String? f(String? s) => s;
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。