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.
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.
- utopia_hooks
State management solution inspired by React Hooks for local and global states.
72Compare - flutterlifecyclehooks
Easily add application lifecycle state hooks using mixins or widgets.
49Compare
Works with
Packages commonly used together with flutter_hooks: ones it builds on, ones built on it, and its own family.
- hooks_riverpodBuilt on flutter_hooksA reactive caching, data-binding, and state management framework with flutter_hooks integration.
- graphql_flutterBuilt on flutter_hooksA GraphQL client for Flutter with widget wrappers and hooks.
- flutter_hooks_testBuilt on flutter_hooksTesting utilities for Flutter hooks that avoid writing wrapper widgets.
- hooked_blocBuilt on flutter_hooksSimplifies Bloc and Cubit usage in Flutter using hooks.
- sliver_snapBuilt on flutter_hooksProvides collapsible and expandable app bars with automatic snapping behaviors.
- flutter_fortune_wheelBuilt on flutter_hooksWidgets for spinning wheels of fortune and fortune bars to visualize random selection.
- stacked_hooksBuilt on flutter_hooksClasses that help use Flutter Hooks with the stacked package architecture.
- flutter_useBuilt on flutter_hooksCollection of 36 production-ready Flutter hooks inspired by react-use.