avoid_unnecessary_hook_widgets
v0.1.0 Warning Fix Widget Best Practices
This rule detects HookWidget subclasses whose build method does not call any hooks (useState, useMemoized, useEffect, etc.). If no hooks are used, the widget should be a plain StatelessWidget instead.
Why use this rule
Section titled “Why use this rule”HookWidget adds a hook management layer on top of the standard widget lifecycle. If you never call any hooks, that layer is pure overhead. Switching to StatelessWidget removes the dependency on flutter_hooks, makes the widget simpler, and signals to readers that no hook-based state management is happening.
See also: flutter_hooks
// HookWidget that never calls any hooksclass Greeting extends HookWidget { @override Widget build(BuildContext context) { return Text('Hello'); }}// StatelessWidget since no hooks are neededclass Greeting extends StatelessWidget { @override Widget build(BuildContext context) { return Text('Hello'); }}Configuration
Section titled “Configuration”This rule is in the opinionated preset, so it is on with
preset: opinionated, or by name:
rules: avoid_unnecessary_hook_widgets: trueTo turn it off again:
rules: avoid_unnecessary_hook_widgets: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_conditional_hooks— Never call hooks inside conditionals, loops, or ternaries.avoid_hooks_outside_build— Only call hooks from a hook context.avoid_misused_hooks— Don’t call hooks inside loops.avoid_returning_widgets— Extract widget helper methods into separate widget classes.