kaeru library
A reactive state management library for Flutter, inspired by Vue Composition API.
Classes
-
AsyncComputed<
T> - A class that computes a value asynchronously and notifies listeners when the value changes.
-
Computed<
T> - A reactive class that computes a value on demand and notifies listeners when the value changes.
- KaeruBuilder
- A widget that provides a KaeruMixin to its builder.
- KaeruBuilderState
- The state for a KaeruBuilder.
-
KaeruWidget<
W extends StatefulWidget> - A widget that provides a reactive context for its children.
-
KaeruWidgetState<
T extends StatefulWidget> - The state for a KaeruWidget.
-
LoadMoreController<
T> - Manages the state and lifecycle of a "load more" request.
- NullWidget
-
PaginationController<
T> - Manages the state and lifecycle of a paginated request.
-
PaginationOptions<
T> - Options for configuring the behavior of usePagination.
-
PaginationResult<
T> - Represents the result of a paginated request.
-
Picker<
T> - A class that memoizes a Computed value.
-
Prop<
T> -
Prop<T>
is a wrapper that allows accessing and updating the value of aRef<T>
. -
Ref<
T> -
A reactive container that holds a single value of type
T
and provides notifications whenever the value changes. -
RequestController<
T> - Manages the state and lifecycle of an asynchronous request.
-
RequestOptions<
T> - Options for configuring the behavior of useRequest.
- UseDark
- A reactive utility to determine if the current theme is dark.
- UseWidgetBox
- A data class holding the reactive box constraints and the builder function.
- UseWidgetSize
- A data class holding the reactive size and the builder function.
- Watch
- A widget that automatically rebuilds when dependencies used inside its builder function change.
Mixins
-
KaeruLifeMixin<
T extends StatefulWidget> -
KaeruLifeMixin
provides Vue-like lifecycle hooks for StatefulWidgets. -
KaeruListenMixin<
T extends StatefulWidget> -
KaeruListenMixin
provides a simple way to listen toChangeNotifier
updates within aStatefulWidget
. -
KaeruMixin<
T extends StatefulWidget> -
A mixin for
State
classes, providing helper methods to create reactive values and computations.
Extensions
-
ValueNotifierToRef
on ValueNotifier<
T> - An extension that allows converting a ValueNotifier to a Ref.
Functions
-
asyncComputed<
T> (Future< T> compute()) → AsyncComputed<T> - Creates an instance of AsyncComputed with the given async function.
-
computed<
T> (T compute()) → Computed< T> -
Creates a reactive Computed with the provided
getter
function. -
nextTick(
[VoidCallback? callback]) → Future< void> - Defers the execution of a callback until the next event loop iteration.
-
onActivated(
VoidCallback callback) → void - Registers a callback to be called when the widget is activated.
-
onBeforeBuild(
void callback(BuildContext context)) → void - Registers a callback to be called before the widget is built.
-
onBeforeUnmount(
VoidCallback callback) → void - Registers a callback to be called before the widget is unmounted.
-
onDeactivated(
VoidCallback callback) → void - Registers a callback to be called when the widget is deactivated.
-
onDebugFillProperties(
void callback(DiagnosticPropertiesBuilder properties)) → void - Registers a callback to be called when the widget's properties are being filled for debugging.
-
onDependenciesChanged(
VoidCallback callback) → void - Registers a callback to be called when the widget's dependencies change.
-
onMounted(
VoidCallback callback) → void - Registers a callback to be called when the widget is first mounted.
-
onUpdated(
void callback(StatefulWidget)) → void - Registers a callback to be called when the widget is updated.
-
onWatcherCleanup(
VoidCallback callback) → void - Registers a cleanup function to be called when the watcher is disposed.
-
ref<
T> (T initialValue) → Ref< T> -
Creates a reactive Ref with the given initial
value
. -
useAnimationController(
{TickerProvider? vsync, Duration? duration, String? debugLabel, double? lowerBound, double? upperBound, double? value, AnimationBehavior animationBehavior = AnimationBehavior.normal}) → AnimationController - Creates an AnimationController.
-
useContext(
) → BuildContext - Retrieves the current BuildContext from the KaeruWidget.
-
useDark(
) → Ref< bool> -
A composable that returns a reactive boolean
Ref
indicating if the current theme is dark. -
useFocusNode(
{String? debugLabel, bool canRequestFocus = true, FocusOnKeyEventCallback? onKeyEvent, bool skipTraversal = false}) → FocusNode - Creates a FocusNode.
-
useFocusScopeNode(
{String? debugLabel}) → FocusScopeNode - Creates a FocusScopeNode.
-
useKaeruContext(
) → KaeruMixin< StatefulWidget> ? - Returns the current KaeruMixin instance.
-
useKeepAliveClient(
{bool wantKeepAlive = true}) → AutomaticKeepAliveClientMixin< StatefulWidget> - A hook that provides an AutomaticKeepAliveClientMixin for keeping a widget alive even when it is not visible.
-
useLifeContext(
) → KaeruLifeMixin< StatefulWidget> ? - Returns the current KaeruLifeMixin instance.
-
useLoadMore<
T> (Future< List< service(int page, T? lastItem)) → LoadMoreController<T> >T> - A composable for managing "load more" or infinite scrolling data fetching.
-
useNotifier<
T extends ChangeNotifier> (T notifier) → T - Creates a ChangeNotifier.
-
useOverlayEntry(
WidgetBuilder builder) → OverlayEntry - Creates an OverlayEntry.
-
usePageController(
{int initialPage = 0, bool keepPage = true, double viewportFraction = 1.0}) → PageController - Creates a PageController.
-
usePagination<
T> (Future< PaginationResult< service(int page, int pageSize), {PaginationOptions<T> >T> options = const PaginationOptions()}) → PaginationController<T> - A composable for managing paginated data fetching.
-
usePick<
T> (T selector()) → Picker< T> - Memoizes a Computed value and returns a Picker that can be used to access the value.
-
usePolling<
T> (Future< T> service(), {Duration interval = const Duration(seconds: 5)}) → RequestController<T> - A composable for managing polling requests.
-
useRequest<
T> (Future< T> service(), {RequestOptions<T> options = const RequestOptions()}) → RequestController<T> - A composable for managing asynchronous data fetching.
-
useRestoration(
{String? restorationId, required void restoreState(RestorationBucket? oldBucket, bool initialRestore), required void didToggleBucket(RestorationBucket? oldBucket), void registerForRestoration(RestorableProperty< Object?> property, String restorationId)?, void unregisterFromRestoration(RestorableProperty<Object?> property)?, VoidCallback? didUpdateRestorationId}) → RestorationMixin<StatefulWidget> - A hook that provides restoration capabilities for widgets.
-
useScrollController(
{double initialScrollOffset = 0.0, bool keepScrollOffset = true, String? debugLabel}) → ScrollController - Creates a ScrollController.
-
useSingleTickerState(
) → TickerProvider - Provides a hook to create a single ticker state for animations.
-
useStream<
T> (Stream< T> stream) → Ref<T?> - Subscribes to a Stream and returns a Ref that is updated with the latest value from the stream.
-
useStreamController<
T> ({bool sync = false}) → StreamController< T> - Creates a StreamController.
-
useStreamDefault<
T> (Stream< T> stream, {required T defaultValue}) → Ref<T> - Subscribes to a Stream and returns a Ref that is updated with the latest value from the stream.
-
useStreamSubscription<
T> (Stream< T> stream, void onData(T event)?, {Function? onError, void onDone()?, bool? cancelOnError}) → StreamSubscription<T> - Creates a StreamSubscription.
-
useTabController(
{required int length, TickerProvider? vsync, int initialIndex = 0, Duration? animationDuration}) → TabController - Creates a TabController.
-
useTextEditingController(
[String? text]) → TextEditingController - Creates a TextEditingController.
-
useTheme(
) → ThemeData -
A composable that returns the current
ThemeData
from the widget tree. -
useTimer(
Duration duration, void callback(), {bool periodic = false}) → Timer - Creates a Timer.
-
useTransformationController(
[Matrix4? value]) → TransformationController - Creates a TransformationController.
-
useValueNotifier<
T> (T value) → ValueNotifier< T> - Creates a ValueNotifier.
-
useWidget<
T extends Widget> () → T - A custom hook to retrieve the current widget of a specific type from the context.
-
useWidgetBox(
) → UseWidgetBox -
A composable that provides the
BoxConstraints
of a widget reactively. -
useWidgetSize(
) → UseWidgetSize -
A composable that provides the
Size
of a widget reactively. -
watch(
Iterable< Listenable?> source, VoidCallback callback, {bool immediate = false}) → VoidCallback -
Sets up a watcher on the given
source
and triggers thecallback
when any of the Listenable objects in the source change. -
watch$(
Iterable< Listenable?> source, VoidCallback callback, {bool immediate = false}) → VoidCallback -
Sets up a watcher on the given
source
and triggers thecallback
when any of the Listenable objects in the source change. Ifimmediate
is true, thecallback
is triggered immediately after setting up the listener. -
watchEffect(
VoidCallback effect) → VoidCallback -
Sets up a reactive effect triggered by
callback
. -
watchEffect$(
VoidCallback callback) → VoidCallback -
Sets up a reactive effect triggered by
callback
and returns a function to dispose of the effect when it’s no longer needed.
Exceptions / Errors
- NoWatcherFoundException
- An exception that is thrown when a reactive function is called outside of a reactive context.