flutter_use library

Functions

useBoolean(bool initialValue) ToggleState
Flutter state hook that tracks value of a bool. useBoolean is an alias for useToggle.
useBuildsCount() int
Tracks component's builds count including the first build.
useCounter(int initialValue, {int? min, int? max}) CounterActions
Flutter state hook that tracks a numeric value. useNumber is an alias for useCounter.
useCustomCompareEffect(Dispose? effect(), List<Object?>? keys, EqualFunction keysEqual) → void
A modified useEffect hook that accepts a comparator which is used for comparison on dependencies instead of reference equality.
useDebounce(VoidCallback fn, Duration delay, [List<Object?>? keys]) → void
Flutter hook that delays invoking a function until after wait milliseconds have elapsed since the last time the debounced function was invoked. The third argument is the array of values that the debounce depends on, in the same manner as useEffect. The debounce timeout will start when one of the values changes.
useDefault<T>(T defaultValue, T initialValue) DefaultState<T>
Flutter state hook that returns the default value when state is null.
useEffectOnce(Dispose? effect()) → void
A modified useEffect(ref link) hook that only runs once. ref link
useError() ErrorState
Returns an error dispatcher.
useException() ExceptionState
Returns an exception dispatcher.
useFirstMountState() bool
Returns true if component is just mounted (on first build) and false otherwise.
useFutureRetry<T>(Future<T>? future, {T? initialData, bool preserveState = true}) FutureState<T>
Uses useFuture with an additional retry method to easily retry/refresh the future function.
useInterval(VoidCallback callback, [Duration? delay = const Duration(milliseconds: 100)]) → void
A declarative interval hook based on Dan Abramov's article(ref link). The interval can be paused by setting the delay to null. ref link
useLatest<T>(T value) → T
React state hook that returns the latest state as described in the React hooks FAQ(ref link). This is mostly useful to get access to the latest value of some props or state inside an asynchronous callback, instead of that value at the time the callback was created from. ref link
useLifecycles({VoidCallback? mount, VoidCallback? unmount}) → void
Flutter lifecycle hook that call mount and unmount callbacks, when component is mounted and un-mounted, respectively. If you want to use hook that app lifecycles, recommended use to flutter_hooks v0.18.1+ useAppLifecycleState(ref link1) or useOnAppLifecycleStateChange(ref link2) ref link1 ref link2
useList<E>(List<E> initialList) ListAction<E>
Tracks an array and provides methods to modify it. To cause component re-build you have to use these methods instead of direct interaction with array - it won't cause re-build. We can ensure that actions object and actions itself will not mutate or change between builds, so there is no need to add it to useEffect dependencies and safe to pass them down to children.
useLogger(String componentName, {Map<String, dynamic> props = const {}}) → void
Flutter lifecycle hook that console logs parameters as component transitions through lifecycles.
useMap<K, V>(Map<K, V> initialMap) MapAction<K, V>
Flutter state hook that tracks a value of a Map.
useMount(VoidCallback fn) → void
Flutter lifecycle hook that calls a function after the component is mounted. Use useLifecycles if you need both a mount and unmount function.
useNumber(int initialValue, {int? min, int? max}) CounterActions
Flutter state hook that tracks a numeric value. useNumber is an alias for useCounter.
useOrientation() Orientation
Tracks screen orientation of user's device.
useOrientationFn(_OrientationCallback onStateChanged) → void
Calls given function changed screen orientation of user's device.
usePreviousDistinct<T>(T value, [Predicate<T>? compare]) → T?
Just like usePrevious but it will only update once the value actually changes. This is important when other hooks are involved and you aren't just interested in the previous props version, but want to know the previous distinct value
useSet<E>(Set<E> initialSet) SetAction<E>
Flutter state hook that tracks a Set.
useStateList<T>([List<T> stateSet = const []]) UseStateList<T>
Provides handles for circular iteration over states list. Supports forward and backward iterations and arbitrary position set.
useTextFormValidator<T>({required Validator validator, required TextEditingController controller, required T initialValue}) → T
Each time given state changes - validator function is invoked.
useTimeout(Duration delay) TimeoutState
Re-builds the component after a specified duration. Provides handles to cancel and/or reset the timeout.
useTimeoutFn(VoidCallback fn, Duration delay) TimeoutState
Calls given function after specified duration. Provides handles to cancel and/or reset the timeout.
useToggle(bool initialValue) ToggleState
Flutter state hook that tracks value of a boolean. useBoolean is an alias for useToggle.
useUnmount(VoidCallback fn) → void
Flutter lifecycle hook that calls a function when the component will unmount. Use useLifecycles if you need both a mount and unmount function.
useUpdate() VoidCallback
Returns a function that forces component to re-build when called.
useUpdateEffect(Dispose? effect(), [List<Object?>? keys]) → void
Flutter effect hook that ignores the first invocation (e.g. on mount). The signature is exactly the same as the useEffect hook.

Typedefs

EqualFunction = bool Function(List<Object?>? prevKeys, List<Object?>? nextKeys)
Predicate<T> = bool Function(T prev, T next)
SnapshotCallback<T> = AsyncSnapshot<T> Function()
Validator<T> = T Function(String value)