Skip to main content

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:​

solid_lints:
diagnostics:
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 (String | List<String> | Map<String, Object?>)​

Types that would be ignored by avoid-late rule Example:

solid_lints:
diagnostics:
avoid_late_keyword:
ignored_types:
- ColorTween
late ColorTween tween; // OK
late int colorValue; // LINT