redus_flutter library

Vue-like Component system for Flutter with reactive state and lifecycle hooks.

This library provides:

  • ReactiveWidget - Reactive widget with customizable State (supports Flutter mixins)
  • Observe - Widget that watches a reactive source and rebuilds when it changes
  • ObserveEffect - Widget that auto-tracks reactive dependencies
  • LifecycleHooksStateMixin and ReactiveStateMixin for custom State classes
  • Lifecycle hooks with Flutter semantics (onInitState, onDispose, etc.)
  • Fine-grained reactivity with .watch(context) extension
  • Dependency injection (register, registerFactory, get) from redus package

Example:

import 'package:redus_flutter/redus_flutter.dart';

class CounterStore {
  final count = ref(0);
  void increment() => count.value++;
}

class Counter extends ReactiveWidget {
  const Counter({super.key});

  @override
  ReactiveState<Counter> createState() => _CounterState();
}

class _CounterState extends ReactiveState<Counter> {
  late final store = CounterStore();

  @override
  void setup() {
    onInitState(() => print('Initialized!'));
    onDispose(() => print('Disposing...'));
  }

  @override
  Widget render(BuildContext context) {
    return GestureDetector(
      onTap: store.increment,
      child: Text('Count: ${store.count.value}'),
    );
  }
}

Classes

Computed<T>
A computed reactive value.
EffectScope
An effect scope for grouping and disposing reactive effects.
GuardAllow
Allow navigation to proceed.
GuardBlock
Block navigation silently.
GuardRedirect
Redirect to a different path.
GuardResult
Result of a guard check.
Observe<T>
A widget that observes a reactive source and rebuilds when it changes.
ObserveEffect
A widget that auto-tracks reactive dependencies and rebuilds when they change.
ObserveMultiple<T>
A widget that observes multiple reactive sources and rebuilds when any change.
ReactiveContext
Manages the relationship between Flutter Elements and ReactiveEffects.
ReactiveEffect
Represents a reactive side effect that re-runs when dependencies change.
ReactiveState<T extends ReactiveWidget>
Base State class for ReactiveWidget.
ReactiveWidget
A StatefulWidget with reactive State that supports custom Flutter mixins.
Readonly<T>
A readonly wrapper around a reactive value.
RedusProvider
Widget that captures Flutter context data for context-free hooks.
RedusRouter
Router interface for navigation.
RedusRouterConfig
Router configuration for use with MaterialApp.router.
Ref<T>
A reactive reference container.
RouteConfig
Configuration for a single route.
RouteGuard
Abstract base class for route guards.
RouteLocation
Represents the current route location with all parsed URL components.
RouteMatch
Result of matching a route against a path.
RouteMatcher
Matches paths against route configurations.
RouterOutlet
Widget that renders child routes for nested routing.
RouterOutletProvider
Provides child route config to RouterOutlet descendants.
RouteTransition
Defines the transition animation for a route.
Scheduler
Scheduler for batching and flushing effects.
ServiceLocator
Service locator for dependency injection.
ShallowReadonly<T>
A shallow readonly wrapper.
ShallowRef<T>
A shallow reactive reference.
UseCupertinoTheme
Property-specific accessors for useCupertinoTheme.
UseMaterialTheme
Property-specific accessors for useMaterialTheme.
UseMediaQuery
Property-specific accessors for useMediaQuery.
WatchHandle
Handle to control a watcher.
WatchOptions
Options for configuring watch behavior.
WritableComputed<T>
A writable computed value.

Enums

FlushMode
Flush timing for effects.
LifecycleTiming
Timing for lifecycle hooks - before or after the lifecycle method.
SlideDirection
Direction for slide transitions.

Mixins

LifecycleCallbacks
Base mixin providing lifecycle callback storage and registration.
LifecycleHooksStateMixin<T extends StatefulWidget>
Mixin providing lifecycle hooks for State classes.
ReactiveStateMixin<T extends StatefulWidget>
Mixin providing automatic reactivity for State classes.

Extensions

ComputedWatchExtension on Computed<T>
Extension to watch Computed values with automatic Element rebuild.
ReadonlyComputed on Computed<T>
Extension to create readonly from Computed.
ReadonlyRef on Ref<T>
Extension to create readonly from Ref.
RefWatchExtension on Ref<T>
Extension to watch Ref values with automatic Element rebuild.
ScopedEffect on ReactiveEffect
Extension to register effects with the current scope.

Properties

activeEffect ReactiveEffect?
The currently active effect being executed.
getter/setter pair
effectStack List<ReactiveEffect>
Stack of active effects for nested effect handling.
final

Functions

computed<T>(T getter()) Computed<T>
Creates a readonly computed value.
customRef<T>(CustomRefFactory<T> factory) Ref<T>
Creates a customized ref with explicit control over dependency tracking.
effectScope({bool detached = false}) EffectScope
Creates an effect scope for grouping reactive effects.
get<T extends Object>({Symbol? key}) → T
Get a registered instance or factory result.
getCurrentScope() EffectScope?
Get the currently active effect scope.
isMarkedRaw(Object? value) bool
Check if an object is marked as raw.
isProxy(Object? value) bool
Check if a value is a reactive proxy (Ref, Computed, Readonly, ShallowRef).
isReactive(Object? value) bool
Check if a value is reactive (Ref, Computed, or ShallowRef).
isReadonly(Object? value) bool
Check if a value is readonly (Readonly or read-only Computed).
isRef(Object? value) bool
Check if a value is a Ref.
isRegistered<T extends Object>({Symbol? key}) bool
Check if a type (and optional key) is registered.
markRaw<T extends Object>(T value) → T
Marks an object so that it will never be converted to a reactive proxy.
onScopeDispose(void callback(), {bool failSilently = false}) → void
Register a dispose callback on the current active effect scope.
onWatcherCleanup(CleanupFn cleanup, {bool failSilently = false}) → void
Register a cleanup function for the current watcher.
readonly<T>(Object source) Readonly<T>
Creates a readonly proxy of a reactive value.
ref<T>(T value) Ref<T>
Creates a reactive reference to a value.
register<T extends Object>(T instance, {Symbol? key}) → void
Register a singleton instance.
registerFactory<T extends Object>(T factory(), {Symbol? key}) → void
Register a factory function.
resetLocator() → void
Reset all registrations.
shallowReadonly<T>(Object source) ShallowReadonly<T>
Creates a shallow readonly wrapper.
shallowRef<T>(T value) ShallowRef<T>
Creates a shallow ref - only .value access is reactive.
toRaw<T>(Object? value) → T
Returns the raw, original value from a reactive wrapper.
toRef<T>(Object source) Ref<T>
Normalizes value/ref/getter to a Ref.
toRefs<T>(Map<String, T> source) Map<String, Ref<T>>
Converts a Map to a Map of Refs.
toValue<T>(Object source) → T
Normalizes values/refs/getters to values.
triggerRef(ShallowRef ref) → void
Force trigger effects that depend on a shallow ref.
unref<T>(Object? maybeRef) → T
Unwrap a Ref to get its value, or return the value as-is if not a Ref.
unregister<T extends Object>({Symbol? key}) → void
Remove a registered instance or factory.
useCupertinoTheme([BuildContext? context]) CupertinoThemeData
Get CupertinoThemeData without context.
useMaterialTheme([BuildContext? context]) ThemeData
Get ThemeData without context.
useMediaQuery([BuildContext? context]) MediaQueryData
Get MediaQueryData without context.
useNavigator([BuildContext? context]) NavigatorState
Get NavigatorState without context.
useRoute() RouteLocation
Get the current route location.
useRouter() RedusRouter
Get the router for navigation.
useScaffoldMessenger([BuildContext? context]) ScaffoldMessengerState
Get ScaffoldMessengerState without context.
watch<T>(T source(), WatchCallback<T> callback, {WatchOptions options = WatchOptions.defaults}) WatchHandle
Watches a reactive source and invokes a callback when it changes.
watchEffect(EffectFn effect, {WatchOptions options = WatchOptions.defaults}) WatchHandle
Runs an effect immediately and re-runs it when dependencies change.
watchMultiple<T>(List<T Function()> sources, void callback(List<T> values, List<T?> oldValues, OnCleanup onCleanup), {WatchOptions options = WatchOptions.defaults}) WatchHandle
Watches multiple sources and invokes callback when any of them change.
watchPostEffect(EffectFn effect) WatchHandle
Alias for watchEffect with flush: FlushMode.post.
watchSyncEffect(EffectFn effect) WatchHandle
Alias for watchEffect with flush: FlushMode.sync.
writableComputed<T>({required T get(), required void set(T value)}) WritableComputed<T>
Creates a writable computed value.

Typedefs

CleanupFn = void Function()
Effect cleanup function type.
CustomRefFactory<T> = ({T Function() get, void Function(T) set}) Function(void track(), void trigger())
Factory function for creating a custom ref.
DidUpdateWidgetCallback<T> = void Function(T oldWidget, T widget)
Callback type for didUpdateWidget - receives oldWidget and current widget.
EffectFn = void Function(OnCleanup onCleanup)
Watch effect function signature.
ErrorCallback = bool? Function(Object error, StackTrace stack)
Callback type for error handling.
InitialRouteRedirect = String Function(String initialRoute)
Signature for redirect function based on initial route.
LifecycleCallback = void Function()
Callback type for lifecycle hooks.
NotFoundBuilder = Widget Function(RouteLocation location)
Signature for the not found page builder.
OnCleanup = void Function(CleanupFn cleanup)
Callback for registering cleanup in effects.
RouteLayoutBuilder = Widget Function(BuildContext context, Widget child)
Signature for the route layout builder function.
SimpleGuard = Future<String?> Function(RouteLocation to, RouteLocation from)
Simple navigation guard function.
WatchCallback<T> = void Function(T value, T? oldValue, OnCleanup onCleanup)
Watch callback signature with new value, old value, and cleanup registration.
WatchGetter<T> = T Function()
Getter function for watch sources.