cast_nullable_to_non_nullable
Don't cast a nullable value to a non nullable type.
This rule is available as of Dart 2.12.
This rule has a quick fix available.
Details
#DON'T cast a nullable value to a non nullable type. This hides a null check and most of the time it is not what is expected.
BAD:
dart
class A {}
class B extends A {}
A? a;
var v = a as B;
var v = a as A;
GOOD:
dart
class A {}
class B extends A {}
A? a;
var v = a! as B;
var v = a!;
Usage
#To enable the cast_nullable_to_non_nullable
rule,
add cast_nullable_to_non_nullable
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- cast_nullable_to_non_nullable
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。