state_beacon_flutter 1.0.0 copy "state_beacon_flutter: ^1.0.0" to clipboard
state_beacon_flutter: ^1.0.0 copied to clipboard

A reactive primitive and simple state managerment solution for dart and flutter

example/README.md

source code with tests: examples/counter/lib/main.dart

class Controller extends BeaconController {
  late final count = B.writable(0);

  void increment() => count.value++;
  void decrement() => count.value--;
}

final countController = Controller();

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('State Beacon Counter without LiteRef'),
          centerTitle: true,
          backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        ),
        body: const Center(child: CounterText()),
        floatingActionButton: const Buttons(),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final count = countController.count;
    final theme = Theme.of(context);
    return Text('$count', style: theme.textTheme.displayLarge);
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      crossAxisAlignment: CrossAxisAlignment.end,
      children: [
        IconButton.filled(
          onPressed: countController.increment,
          icon: const Icon(Icons.add),
          iconSize: 32,
        ),
        const SizedBox(height: 8),
        IconButton.filled(
          onPressed: countController.decrement,
          icon: const Icon(Icons.remove),
          iconSize: 32,
        ),
      ],
    );
  }
}
1
likes
160
points
361
downloads

Publisher

verified publishernosy.dev

Weekly Downloads

A reactive primitive and simple state managerment solution for dart and flutter

Repository (GitHub)
View/report issues

Topics

#state-management #signal #reactive #beacon

Documentation

API reference

License

MIT (license)

Dependencies

flutter, state_beacon_core

More

Packages that depend on state_beacon_flutter