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

A lightweight, reactive state management solution for Flutter applications with built-in history tracking, validation, debouncing, and throttling capabilities.

example/lib/main.dart

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

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

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

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

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

  @override
  State<CounterPage> createState() => _CounterPageState();
}

class _CounterPageState extends State<CounterPage> {
  late final ValueState<int> counter;

  @override
  void initState() {
    super.initState();
    counter = state(0);
  }

  @override
  void dispose() {
    counter.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            // Counter display using Observer
            Observer(
              state: counter,
              builder:
                  (context, value) => Text(
                'Count: $value',
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            ),
            const SizedBox(height: 20),

            // Action buttons
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ElevatedButton(
                  onPressed: () => counter.decrement(),
                  child: const Text('Decrement'),
                ),
                const SizedBox(width: 16),
                ElevatedButton(
                  onPressed: () => counter.increment(),
                  child: const Text('Increment'),
                ),
              ],
            ),
            const SizedBox(height: 20),
          ],
        ),
      ),
    );
  }
}
4
likes
160
points
30
downloads

Publisher

verified publisherflutteroiditservices.in

Weekly Downloads

A lightweight, reactive state management solution for Flutter applications with built-in history tracking, validation, debouncing, and throttling capabilities.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on microstate