mu_state 0.4.0+4 copy "mu_state: ^0.4.0+4" to clipboard
mu_state: ^0.4.0+4 copied to clipboard

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

mu_state #

A minimal state solution based on my Pragmatic state handling in Flutter Medium article .

Features #

A set of classes built on ValueNotifier and ValueListenableBuilder for handling state in Flutter.

  • MuLogic - an alias for ValueNotifier where you can optionally use a MuState<T> type
  • MuBuilder - an alias for ValueListenableBuilder
  • MuEvent<T> - the base class for 3 state object which can be used in a MuState<T>:
    • MuEventData<T> - the data state of type T
    • MuEventError - the error state
    • MuEventLoading - the loading state
  • MuMultiBuilder - listen to changes of a list of Listenable objects

How To #

Contain state by inheriting from MuLogic or using it directly. This can have any type.

You can use an optional MuEvent type MuLoading, MuError or MuData to contain the state.

Listen to MuLogic changes using MuBuilder.

Listen to multiple MuLogic objects using MuMultiBuilder.

Example #

In test_state.dart:

import 'package:mu_state/mu_state.dart';

class CounterLogic extends MuState<int> {
  CounterLogic(super.initValue);

  void increment() {
    value = value + 1;
  }
}

final counterState = CounterState(0);

In main.dart:

Scaffold(
  body: Center(
    child: MuBuilder(
      state: counterState,
      builder: (context, event, child) {
        return Text('$value');
      },
    ),
  ),
),

See more examples in Example.

2
likes
160
points
24
downloads

Publisher

verified publisherapptakk.com

Weekly Downloads

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