use_late_for_private_fields_and_variables
Use late for private members with a non-nullable type.
This rule is currently experimental and available as of Dart 2.10.
Details
#Use late
for private members with non-nullable types that are always expected
to be non-null. Thus it's clear that the field is not expected to be null
and it avoids null checks.
BAD:
dart
int? _i;
m() {
_i!.abs();
}
GOOD:
dart
late int _i;
m() {
_i.abs();
}
OK:
dart
int? _i;
m() {
_i?.abs();
_i = null;
}
Usage
#To enable the use_late_for_private_fields_and_variables
rule,
add use_late_for_private_fields_and_variables
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- use_late_for_private_fields_and_variables
除非另有说明,文档之所提及适用于 Dart 3.5.3 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。