shared_value 0.1.0 copy "shared_value: ^0.1.0" to clipboard
shared_value: ^0.1.0 copied to clipboard

outdated

A straightforward way to manage global state in flutter apps.

pub package

Shared Value #

A wrapper over InheritedModel, this module allows users to easily share global state between multiple widgets.

Usage #

  1. Initialize
main() {
    /// Insert Shared Value into the widget tree.
    runApp(SharedValue.wrapApp(MyApp()));
}

/// Create a Shared Value object that holds the value of a counter.
/// ("counter" is used as key for shared_preferences).
var counter = SharedValue("counter", value: 0);
  1. Use
/// Use [counter] anywhere.
print(counter.value);

/// Muatate [counter] anywhere.
counter.mutate((value) {
    return value + 1;
});

/// Rebuild [MyWidget] whenever [counter] changes.
class MyWidgetState extends State<MyWidget> {
    @override
    Widget build(BuildContext context) {
        counterValue = counter.of(context);
        ...
    }
}
  1. Persist
/// Store [counter] value to shared preferences.
counter.load();

/// Load [counter] value from shared preferences.
counter.store();
17
likes
0
pub points
94%
popularity

Publisher

unverified uploader

A straightforward way to manage global state in flutter apps.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, shared_preferences

More

Packages that depend on shared_value