flutter_reduct 1.0.1 copy "flutter_reduct: ^1.0.1" to clipboard
flutter_reduct: ^1.0.1 copied to clipboard

An elementary yet adaptable state management solution for Dart.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:reduct/reduct.dart';
import 'package:flutter_reduct/flutter_reduct.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Reduct',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Reduct'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(title),
      ),
      body: AtomListener<int>(
        atom: counterState,
        listener: (context, value) {
          final snackBar = SnackBar(content: Text('Counter: $value'));
          ScaffoldMessenger.of(context).showSnackBar(snackBar);
        },
        child: Center(
          child: AtomBuilder<int>(
            atom: counterState,
            builder: (context, value) => Text(
              'Counter: $value',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: incrementAction.call,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

// atoms
final counterState = Atom(0);
final incrementAction = Atom.action();

// reducer
class CounterReducer extends Reducer {
  CounterReducer() {
    on(incrementAction, (_) => counterState.value++);
  }
}
2
likes
160
points
26
downloads

Publisher

verified publishereronsoft.com

Weekly Downloads

An elementary yet adaptable state management solution for Dart.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, reduct

More

Packages that depend on flutter_reduct