Skip to content
pubscout

flutter_hooks

0.21.4, released 2 weeks ago by dash-overflow.net

A Flutter implementation of React hooks for managing widget life-cycle and code reuse.

WASM-ready
$ flutter pub add flutter_hooks
Source repository

What it does

It introduces a new kind of object (hooks) that manage the life-cycle of a widget, allowing you to extract and share stateful logic like AnimationControllers across widgets without using complex mixins.

AI-written summary of version 0.21.4, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want to share stateful logic across multiple widgets without boilerplate.
  • You prefer a hooks-based architecture similar to React inside Flutter's build methods.

Skip it when

  • You rely heavily on standard StatefulWidget structures and do not want to adopt a hooks paradigm.
  • You are working with complex conditional hook calls (hooks must be called unconditionally).

Strengths

  • Increases code-sharing between widgets by removing duplicate lifecycle boilerplate.
  • Extracted logic can be easily packaged and published independently.

Weaknesses

  • Requires strict adherence to rules (calling hooks unconditionally and prefixing with 'use').
  • Hot-reload behavior can cause hard-resets of hooks if hooks are removed or reordered incorrectly.

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
0

not documented

class Example extends HookWidget {
  const Example({super.key, required this.duration});

  final Duration duration;

  @override
  Widget build(BuildContext context) {
    final controller = useAnimationController(duration: duration);
    return Container();
  }
}

Alternatives

Packages that do the same job and could replace flutter_hooks.

Works with

Packages commonly used together with flutter_hooks: ones it builds on, ones built on it, and its own family.