avoid-late-context
- Group
- Correctness
- Path
lint/correctness/avoid-late-context- Default
- On (recommended)
- Origin
- Falcon
- Domain
- flutter
- Rule
- 81 of 512
Avoid storing BuildContext in late fields or reading it in late initializers. Resolved Flutter context values are checked rather than identifier spelling.
Invalid
import 'package:flutter/material.dart';
class S extends State<StatefulWidget> {
late final value0 = context;
late BuildContext value1;
late final value2 = this.context;
late final value3 = Theme.of(context);
late final BuildContext value4 = context;
}class S extends State<StatefulWidget> {late final value0 = context;late final value0 = context;late BuildContext value1;late BuildContext value1;late final value2 = this.context;late final value2 = this.context;late final value3 = Theme.of(context);late final value3 = Theme.of(context);late final BuildContext value4 = context;Valid
import 'package:flutter/material.dart';
class S extends State<StatefulWidget> {
late final value0 = 0;
late final value1 = 'text';
late final value2 = <String>[];
BuildContext? value3;
BuildContext get value4 => context;
}Configure avoid-late-context
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"avoid-late-context": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/avoid-late-context: <reason>More correctness rules
- avoid-missing-completer-stack-trace
Preserve error origins when calling SDK
Completer.completeError. - avoid-missing-controllerflutter
Require Flutter text fields to expose their updated value.
- avoid-missing-enum-constant-in-map
Require enum-keyed map literals to include every declared enum value.
- avoid-missing-interpolationrecommended
Flags missing interpolation around visible String variables or member accesses and calls.
- avoid-misused-hooksrecommendedflutter_hooks
Flags confirmed Flutter hooks called directly in non-hook Flutter widget builds.
- avoid-mounted-in-setstateflutter
Check mounted before invoking Flutter State.setState, never inside its callback.
- avoid-mutable-equatable-subclass-fieldsrecommendedequatable
Flags mutable instance fields on subclasses inheriting Equatable equality.
- avoid-mutable-global-variables
avoid_mutable_global_variablesDisallow mutable top-level variables.