mu_state 0.5.0+5 copy "mu_state: ^0.5.0+5" to clipboard
mu_state: ^0.5.0+5 copied to clipboard

A set of helpers for pragmatic state handling as mentioned in my Medium article.

example/lib/main.dart

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

import 'states/auto_counter_state.dart';
import 'states/counter_state.dart';
import 'states/load_state.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

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

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('mu_state example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Padding(
              padding: const EdgeInsets.all(16),
              child: MuBuilder(
                valueListenable: counterState,
                builder: (context, value, child) => Text('$value'),
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(16),
              child: MuMultiBuilder(
                listenables: [counterState, autoCounterState, loadState],
                builder: (context, values, child) {
                  return Column(
                    children: [
                      Text('counter: ${counterState.value}'),
                      Text('auto counter: ${autoCounterState.value}'),
                      Text(
                        'load state: ${switch (loadState.value) {
                          MuLoading() => 'loading',
                          MuError(error: Object error) => 'error: $error',
                          MuData(data: String message) => message,
                        }}',
                      ),
                    ],
                  );
                },
              ),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          counterState.increment();
          loadState.load();
        },
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
2
likes
160
pub points
22%
popularity

Publisher

verified publisherapptakk.com

A set of helpers for pragmatic state handling as mentioned in my Medium article.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on mu_state