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.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:obs_state_mixin/obs_state_mixin.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Flutter Obs State Demo',
      home: Home(),
    );
  }
}

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