obs_state_mixin 0.0.1-dev.6 copy "obs_state_mixin: ^0.0.1-dev.6" to clipboard
obs_state_mixin: ^0.0.1-dev.6 copied to clipboard

Lightweight Flutter package for reactive state management using Obs and ObsStateMixin.

obs_state_mixin #

deploy codecov Pub Version GitHub License GitHub last commit Pub Points

obs_state_mixin is a lightweight Flutter package for reactive state management. It provides an Obs class for observable values and ObsStateMixin to simplify automatic UI updates and resource cleanup in StatefulWidget.

Features #

  • Create observable field with ObsStateMixin.
  • Automatically listen to state changes and trigger setState().
  • Automatically dispose the observable when the widget is disposed.

Installation #

Add the package to your pubspec.yaml:

dependencies:
  obs_state_mixin: ^0.0.1-dev.6

Run flutter pub get to fetch the package.

Usage #

class Home extends StatefulWidget {
  const Home({super.key});

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> with ObsStateMixin {
  // Creates a new observable called _counter.
  // This will automatically be disposed when the widget is disposed.
  late final _counter = obs(0);

  // Increments the value of _counter. No need to call setState().
  void _incrementCounter() => _counter.value++;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
0
likes
160
points
25
downloads

Publisher

verified publisheralbinpk.dev

Weekly Downloads

Lightweight Flutter package for reactive state management using Obs and ObsStateMixin.

Repository (GitHub)
View/report issues
Contributing

Topics

#observable #reactive #state-management #obs #state-mixin

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on obs_state_mixin