avoid_late_keyword
Avoid late
keyword
Using late
disables compile time safety for what would else be a nullable
variable. Instead, a runtime check is made, which may throw an unexpected
exception for an uninitialized variable.
Example config:
custom_lint:
rules:
- avoid_late_keyword:
allow_initialized: false
ignored_types:
- AnimationController
- ColorTween
Example
BAD:
class AvoidLateKeyword {
late final int field; // LINT
void test() {
late final local = ''; // LINT
}
}
GOOD:
class AvoidLateKeyword {
final int? field; // LINT
void test() {
final local = ''; // LINT
}
}
Parameters
allow_initialized (bool)
Allow immediately initialized late variables.
late var ok = 0; // ok when allowInitialized == true
late var notOk; // initialized elsewhere, not allowed
ignored_types (Iterable<String>)
Types that would be ignored by avoid-late rule
Example:
custom_lint:
rules:
- avoid_late_keyword:
ignored_types:
- ColorTween
late ColorTween tween; // OK
late int colorValue; // LINT