flutter_reacton 0.2.0 copy "flutter_reacton: ^0.2.0" to clipboard
flutter_reacton: ^0.2.0 copied to clipboard

Flutter widgets and bindings for the Reacton state management library. Provides ReactonScope, ReactonBuilder, context.watch(), and more.

flutter_reacton #

Flutter widgets and bindings for the Reacton state management library. Provides ReactonScope, context.watch(), ReactonBuilder, ReactonConsumer, ReactonListener, ReactonSelector, and automatic disposal.

Installation #

dependencies:
  flutter_reacton: ^0.2.0

flutter_reacton re-exports package:reacton/reacton.dart, so you only need this single dependency.

Quick Start #

import 'package:flutter_reacton/flutter_reacton.dart';

// 1. Define reactons at the top level
final counterReacton = reacton(0, name: 'counter');

// 2. Wrap your app in ReactonScope
void main() => runApp(ReactonScope(child: MyApp()));

// 3. Use in widgets
class CounterPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final count = context.watch(counterReacton);

    return Scaffold(
      body: Center(child: Text('Count: $count')),
      floatingActionButton: FloatingActionButton(
        onPressed: () => context.update(counterReacton, (n) => n + 1),
        child: Icon(Icons.add),
      ),
    );
  }
}

Widgets #

ReactonScope #

Provides the ReactonStore to all descendants. Must wrap your app or the subtree that uses Reacton.

ReactonScope(
  store: ReactonStore(), // optional, creates one if omitted
  child: MyApp(),
)

context.watch() #

Reads a reacton and subscribes the widget to changes. The widget rebuilds when the reacton value changes.

final count = context.watch(counterReacton);

context.read() #

Reads a reacton without subscribing. Use this in event handlers, not in build().

onPressed: () {
  final current = context.read(counterReacton);
  context.set(counterReacton, current + 1);
}

context.set() #

Sets a writable reacton's value.

context.set(counterReacton, 42);

context.update() #

Updates a writable reacton using a function.

context.update(counterReacton, (count) => count + 1);

ReactonBuilder #

A widget that rebuilds when a specific reacton changes. Useful when you need a builder pattern instead of context.watch().

ReactonBuilder<int>(
  reacton: counterReacton,
  builder: (context, count) => Text('$count'),
)

ReactonConsumer #

Exposes a ReactonWidgetRef that can watch, read, set, and update multiple reactons inside a single builder.

ReactonConsumer(
  builder: (context, ref) {
    final count = ref.watch(counterReacton);
    return ElevatedButton(
      onPressed: () => ref.update(counterReacton, (c) => c + 1),
      child: Text('$count'),
    );
  },
)

ReactonListener #

Listens to a reacton and runs a callback on change without rebuilding. Useful for navigation, snackbars, and other side effects.

ReactonListener<String>(
  reacton: errorReacton,
  listener: (context, error) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(content: Text(error)),
    );
  },
  child: MyPage(),
)

ReactonSelector #

Watches a sub-value of a reacton and only rebuilds when the selected value changes.

ReactonSelector<User, String>(
  reacton: userReacton,
  selector: (user) => user.name,
  builder: (context, name) => Text(name),
)

Auto-Dispose #

Reacton automatically cleans up reacton subscriptions when widgets are removed from the tree. No manual dispose() calls are needed for context.watch() subscriptions.

Documentation #

See the Reacton documentation for full API reference and guides. Source at https://github.com/sitharaj88/reacton.

License #

MIT

0
likes
160
points
48
downloads

Documentation

API reference

Publisher

verified publishersitharaj.in

Weekly Downloads

Flutter widgets and bindings for the Reacton state management library. Provides ReactonScope, ReactonBuilder, context.watch(), and more.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, reacton

More

Packages that depend on flutter_reacton