watch_x 0.0.1 copy "watch_x: ^0.0.1" to clipboard
watch_x: ^0.0.1 copied to clipboard

A lightweight reactive state management for Flutter with fine-grained field watchers.

WatchX #

Pub Version License Pub points Pub Likes Pub popularity

WatchX is a lightweight, reactive state management solution for Flutter that allows you to "watch" individual fields and automatically rebuild your widgets when the values change.

It uses ValueNotifier under the hood to provide fine-grained reactivity without the boilerplate of larger state-management tools.


Installation #

Add the following to your pubspec.yaml:

watch_x: ^latest_version

Then run flutter pub get to install the package.


Example Usage #

import 'package:watch_x/watch_x.dart'; // -> import

// initialise your watchers with default values
WatchX watchx = WatchX({
  "counter": 0,
  "name": "Yung",
});

// update the value via watch() giving it a key
watchx.watch("counter")!.value++;

watchx.watch("name")!.value = "New Name";

// Listen to changes in the UI
XListenableBuilder(
  watchers: watchx.watchers,
  builder: (context, values) {
    return Column(
        mainAxisSize: MainAxisSize.min,
        children: [
            const Text('Counter: ${values["counter"]}'),
            Text('Name: ${values["name"]}',
                style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
            ),
        ],
    );
  },
);

Using Provider for Global Access #

You can also use Provider to make WatchX accessible throughout your widget tree.

void main() {
  runApp(Provider(
    create: (_) => WatchX({"counter": 0, "name": "Yung"}),
    child: const MyApp(),
  ));
}

Then, in your widgets, you can access the WatchX instance like this:

// Accessing WatchX in your widgets
final watchx = Provider.of<WatchX>(context);    

watchx.watch("counter")!.value++; // update counter

// Listen to changes in the UI
XListenableBuilder(
  watchers: watchx.watchers,
  builder: (context, values) {
    return Text('Counter: ${values["counter"]}');
  },
);

Licensing #

This project is licensed under the MIT License - see the LICENSE file for details.

0
likes
160
points
0
downloads

Publisher

verified publisherpermanentlink.co.za

Weekly Downloads

A lightweight reactive state management for Flutter with fine-grained field watchers.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on watch_x