obs_state_mixin 0.0.1-dev.4 copy "obs_state_mixin: ^0.0.1-dev.4" to clipboard
obs_state_mixin: ^0.0.1-dev.4 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.4

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
0
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

Topics

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

License

unknown (license)

Dependencies

flutter

More

Packages that depend on obs_state_mixin