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

outdated

A straightforward way to manage global state in flutter apps.

pub package

Shared Value #

A wrapper over flutter's InheritedModel, shared value allows users to easily share a global state value between multiple widgets.

Usage #

  • initiate
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);
  • use
/// Use `counter` anywhere.
print(counter.value);

/// Muatate `counter` anywhere.
counter.mutate((value) {
    value += 1;
});

/// Rebuild widgets whenever `counter` changes.
class MyWidgetState extends State<MyWidget> {
    @override
    Widget build(BuildContext context) {
        counterValue = counter.of(context);
        ...
    }
}
  • persist
/// Store counter to shared preferences.
counter.load();

/// Load counter's value from shared preferences.
counter.store();
17
likes
0
pub points
93%
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