avoid-inherited-widget-in-initstate
- Group
- Correctness
- Path
lint/correctness/avoid-inherited-widget-in-initstate- Default
- On (recommended)
- Origin
- Falcon
- Domain
- flutter
- Rule
- 75 of 512
Avoid inherited-widget subscriptions during initState. Checks direct BuildContext dependency calls and known subscribing Flutter of methods, including synchronous local helper calls.
Invalid
import 'package:flutter/material.dart';
class S extends State<StatefulWidget> { void initState() {
Theme.of(context);
MediaQuery.of(context);
Directionality.of(context);
DefaultTextStyle.of(context);
IconTheme.of(context);
}}class S extends State<StatefulWidget> { void initState() {Theme.of(context);Theme.of(context);MediaQuery.of(context);MediaQuery.of(context);Directionality.of(context);Directionality.of(context);DefaultTextStyle.of(context);DefaultTextStyle.of(context);IconTheme.of(context);Valid
import 'package:flutter/material.dart';
class S extends State<StatefulWidget> { void didChangeDependencies() {
Theme.of(context);
MediaQuery.of(context);
Directionality.of(context);
DefaultTextStyle.of(context);
IconTheme.of(context);
}}Configure avoid-inherited-widget-in-initstate
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"avoid-inherited-widget-in-initstate": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/avoid-inherited-widget-in-initstate: <reason>More correctness rules
- avoid-instantiating-in-value-providerprovider
Value providers borrow existing instances; newly constructed values need create.
- avoid-late-contextrecommendedflutter
Avoid storing
BuildContextin late fields or reading it in late initializers. - 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.