Stable null-safety release
Migrated flutter_hooks to null-safety (special thanks to @DevNico for the help!)
- Added
usePageController
to create aPageController
-
Increased the minimum version of the Flutter SDK required to match changes on
useFocusNode
The minimum required is now 1.20.0 (the stable channel is at 1.20.4)
- added all
FocusNode
parameters touseFocusNode
- Fixed a bug where on hot-reload, a
HookWidget
could potentailly not rebuild - Allow hooks to integrate with the devtool using the
Diagnosticable
API, and implement it for all built-in hooks.
useIsMounted
now returns a function instead of a callable class.
- Added
useIsMounted
to determine whether a widget was destroyed or not (thanks to @davidmartos96)
- Added
useScrollController
to create aScrollController
- added
useTabController
to create aTabController
(thanks to @Albert221)
Breaking change:
- Removed
HookState.didBuild
.
If you still need it, useaddPostFrameCallback
orFuture.microtask
.
Non-breaking changes:
-
Fix a bug where the order in which hooks are disposed is incorrect.
-
It is now allowed to rebuild a
HookWidget
with more/less hooks than previously. Example:Widget build(context) { useSomething(); if (condition) { return Container(); } useSomething() return Container(); }
-
Deprecated
Hook.use
in favor of a new short-handuse
. Before:Hook.use(MyHook());
After:
use(MyHook());
Breaking change:
-
The order in which hooks are disposed has been reversed.
Consider:
useSomething(); useSomethingElse();
Before, the
useSomething
was disposed beforeuseSomethingElse
. Now,useSomethingElse
is disposed before theuseSomething
.The reason for this change is for cases like:
// Creates an AnimationController final animationController = useAnimationController(); // Immediatly listen to the AnimationController useListenable(animationController);
Before, when the widget was disposed, this caused an exception as
useListenable
unsubscribed to theAnimationController
after itsdispose
method was called.
Non-breaking changes:
- Added a way for hooks to potentially abort a widget rebuild.
- Added
StatefulHookWidget
, aStatefulWidget
that can use hooks inside itsbuild
method.
- Added a
deactivate
life-cycle toHookState
- Fixed link to "Existing hooks" in
README.md
.
Added useFocusNode
- Added
useTextEditingController
, thanks to simolus3!
- Added
useReassemble
hook, thanks to @SahandAkbarzadeh
- Make hooks compatible with newer flutter stable version 1.7.8-hotfix.2.
- Make hooks compatible with newer flutter version. (see https://groups.google.com/forum/#!topic/flutter-announce/hp1RNIgej38)
- NEW:
usePrevious
, a hook that returns the previous argument is received. - NEW: it is now impossible to call
inheritFromWidgetOfExactType
insideinitHook
of hooks. This forces authors to handle value updates. - FIX: use List instead of List for keys. This fixes
implicit-dynamic
rule mistakenly reporting errors. - NEW: Hooks are now visible on
HookElement
throughdebugHooks
in development, for testing purposes. - NEW: If a widget throws on the first build or after a hot-reload, next rebuilds can still add/edit hooks until one
build
finishes entirely. - NEW: new life-cycle available on
HookState
:didBuild
. This life-cycle is called synchronously right afterbuild
method ofHookWidget
finished. - NEW: new
reassemble
life-cycle onHookState
. It is equivalent toState.ressemble
of statefulwidgets. - NEW:
useStream
anduseFuture
now have an optionalpreserveState
flag. This toggle how these hooks behave when changing the stream/future: If true (default) they keep the previous value, else they reset to initialState. - NEW:
useValueNotifier
, which creates aValueNotifier
similarly touseState
. But without listening it. This can be useful to have a more granular rebuild when combined touseValueListenable
. - NEW:
useContext
, which exposes theBuildContext
of the currently buildingHookWidget
. - Made all existing hooks as static functions, and removed
HookContext
. The migration is as followed: - Introduced keys for hooks and applied them to hooks where it makes sense.
- Added
useReducer
for complex state. It is similar touseState
but is being managed by aReducer
and can only be changed by dispatching an action. - fixes a bug where hot-reload without using hooks thrown an exception
useMemoized
callback doesn't take the previous value anymore (to match React API) UseuseValueChanged
instead.- Introduced
useEffect
anduseStreamController
- fixed a bug where hot-reload while reordering/adding hooks did not work properly
- improved readme
useStream
useFuture
useAnimationController
useSingleTickerProvider
useListenable
useValueListenable
useAnimation
- initial release
Widget build(HookContext context) {
final state = context.useState(0);
}
becomes:
Widget build(BuildContext context) {
final state = useState(0);
}
Added a few common hooks: