leancode_hooks library

Classes

Hook<R>
Hook is similar to a StatelessWidget, but is not associated to an Element.
HookBuilder
A HookWidget that delegates its build to a callback.
HookState<R, T extends Hook<R>>
The logic and internal state for a HookWidget
HookWidget
A Widget that can use a Hook.
ObjectRef<T>
A class that stores a single value.
StatefulHookWidget
A StatefulWidget that can use a Hook.
Store<State, Action>
A store of mutable state that allows mutations by dispatching actions.
TapGestureRecognizer
Recognizes taps.

Mixins

HookElement
An Element that uses a HookWidget as its configuration.

Constants

useTextEditingController → const _TextEditingControllerHookCreator
Creates a TextEditingController, either via an initial text or an initial TextEditingValue.

Properties

debugHotReloadHooksEnabled bool
Whether to behave like in release mode or allow hot-reload for hooks.
getter/setter pair

Functions

use<R>(Hook<R> hook) → R
Registers a Hook and returns its value.
useAnimation<T>(Animation<T> animation) → T
Subscribes to an Animation and returns its value.
useAnimationController({Duration? duration, Duration? reverseDuration, String? debugLabel, double initialValue = 0, double lowerBound = 0, double upperBound = 1, TickerProvider? vsync, AnimationBehavior animationBehavior = AnimationBehavior.normal, List<Object?>? keys}) AnimationController
Creates an AnimationController and automatically disposes it when necessary.
useAppLifecycleState() AppLifecycleState?
Returns the current AppLifecycleState value and rebuilds the widget when it changes.
useAutomaticKeepAlive({bool wantKeepAlive = true}) → void
Mark a widget using this hook as needing to stay alive even when it's in a lazy list that would otherwise remove it.
useBloc<B extends BlocBase<Object?>>(B create(), [List<Object?> keys = const []]) → B
Provides a Cubit or a Bloc that is automatically disposed without having to use BlocProvider.
useBlocListener<S>({required BlocBase<S> bloc, required void listener(S state)}) → void
Takes a Bloc or Cubit and invokes listener in response to state changes.
useBlocState<S>(BlocBase<S> bloc) → S
Provides Cubit's or Bloc's current state. Forces HookWidget to rebuild on state change.
useCallback<T extends Function>(T callback, List<Object?> keys) → T
Cache a function across rebuilds based on a list of keys.
useContext() BuildContext
Obtains the BuildContext of the building HookWidget.
useDebounce(Duration duration) DebouncedCallback
Returns a function whose invocation will be delayed by duration.
useDeclarativeTextEditingController({required String text}) TextEditingController
A wrapper around useTextEditingController that updates TextEditingController.text when the text changes.
useEffect(Dispose? effect(), [List<Object?>? keys]) → void
Useful for side-effects and optionally canceling them.
useFocused(FocusNode focusNode) bool
Subscribes to focusNode changes and marks the widget as needing build whenever they happen. Returns whether focusNode has focus.
useFocusNode({String? debugLabel, FocusOnKeyCallback? onKey, FocusOnKeyEventCallback? onKeyEvent, bool skipTraversal = false, bool canRequestFocus = true, bool descendantsAreFocusable = true}) FocusNode
Creates an automatically disposed FocusNode.
useFocusScopeNode({String? debugLabel, FocusOnKeyCallback? onKey, FocusOnKeyEventCallback? onKeyEvent, bool skipTraversal = false, bool canRequestFocus = true}) FocusScopeNode
Creates an automatically disposed FocusScopeNode.
useFuture<T>(Future<T>? future, {T? initialData, bool preserveState = true}) AsyncSnapshot<T>
Subscribes to a Future and returns its current state as an AsyncSnapshot.
useIsMounted() IsMounted
Returns an IsMounted object that you can use to check if the State is mounted.
useListenable<T extends Listenable?>(T listenable) → T
Subscribes to a Listenable and marks the widget as needing build whenever the listener is called.
useListenableSelector<R>(Listenable listenable, R selector()) → R
Rebuild only when there is a change in the selector result.
useMemoized<T>(T valueBuilder(), [List<Object?> keys = const <Object>[]]) → T
Caches the instance of a complex object.
useOnAppLifecycleStateChange(LifecycleCallback? onStateChanged) → void
Listens to the AppLifecycleState.
useOnPlatformBrightnessChange(BrightnessCallback onBrightnessChange) → void
Listens to the platform Brightness.
usePageController({int initialPage = 0, bool keepPage = true, double viewportFraction = 1.0, List<Object?>? keys}) PageController
Creates a PageController that will be disposed automatically.
usePlatformBrightness() Brightness
Returns the current platform Brightness value and rebuilds the widget when it changes.
usePostFrameEffect(VoidCallback effect, [List<Object?>? keys]) → void
Registers effect to be run in WidgetsBinding.instance.addPostFrameCallback.
usePrevious<T>(T val) → T?
Returns the previous value passed to usePrevious (from the previous widget build).
useReassemble(VoidCallback callback) → void
Runs the callback on every hot reload, similar to reassemble in the stateful widgets.
useReducer<State, Action>(Reducer<State, Action> reducer, {required State initialState, required Action initialAction}) Store<State, Action>
An alternative to useState for more complex states.
useRef<T>(T initialValue) ObjectRef<T>
Creates an object that contains a single mutable property.
useScrollController({double initialScrollOffset = 0.0, bool keepScrollOffset = true, String? debugLabel, List<Object?>? keys}) ScrollController
Creates ScrollController that will be disposed automatically.
useSingleTickerProvider({List<Object?>? keys}) TickerProvider
Creates a single usage TickerProvider.
useState<T>(T initialData) ValueNotifier<T>
Creates a variable and subscribes to it.
useStream<T>(Stream<T>? stream, {T? initialData, bool preserveState = true}) AsyncSnapshot<T>
Subscribes to a Stream and returns its current state as an AsyncSnapshot.
useStreamController<T>({bool sync = false, VoidCallback? onListen, VoidCallback? onCancel, List<Object?>? keys}) StreamController<T>
Creates a StreamController which is automatically disposed when necessary.
useStreamListener<T>(Stream<T> stream, ValueChanged<T> onData, {Function? onError, void onDone()?, bool? cancelOnError, List<Object?> keys = const []}) → void
Listens to stream and calls onData on new data.
useSyncedTextEditingController(void onChanged(TextEditingValue value), {String? initialText}) TextEditingController
A wrapper around useTextEditingController that makes it easier to add onChanged callback to TextEditingController.
useTabController({required int initialLength, TickerProvider? vsync, int initialIndex = 0, List<Object?>? keys}) TabController
Creates a TabController that will be disposed automatically.
useTapGestureRecognizer(TapGestureRecognizer builder(), [List<Object?> keys = const []]) TapGestureRecognizer
Creates a TapGestureRecognizer that will be disposed automatically.
useThrottle(Duration duration) ThrottledCallback
Returns a function that is throttled for duration after being called.
useTransformationController({Matrix4? initialValue, List<Object?>? keys}) TransformationController
Creates and disposes a TransformationController.
useValueChanged<T, R>(T value, R? valueChange(T oldValue, R? oldResult)) → R?
Watches a value and triggers a callback whenever the value changed.
useValueListenable<T>(ValueListenable<T> valueListenable) → T
Subscribes to a ValueListenable and returns its value.
useValueNotifier<T>(T initialData, [List<Object?>? keys]) ValueNotifier<T>
Creates a ValueNotifier that is automatically disposed.

Typedefs

BrightnessCallback = FutureOr<void> Function(Brightness previous, Brightness current)
A callback triggered when the platform brightness changes.
DebouncedCallback = void Function(VoidCallback callback)
Signature of function that is returned by useDebounce.
Dispose = void Function()
A function called when the state of a widget is destroyed.
IsMounted = bool Function()
Used by useIsMounted to allow widgets to determine if the Widget is still in the widget tree or not.
LifecycleCallback = FutureOr<void> Function(AppLifecycleState? previous, AppLifecycleState current)
A callback triggered when the app life cycle changes.
Reducer<State, Action> = State Function(State state, Action action)
Composes an Action and a State to create a new State.
ThrottledCallback = void Function(VoidCallback callback)
Signature of function that is returned by useThrottle.