shared_value
3.0.0, released 4 years ago by an unverified publisher
Manage global state and persist variables using InheritedModel.
What it does
A wrapper over InheritedModel that lets you manage global state in Flutter apps with low boilerplate. It can be used anywhere in Dart code even without a BuildContext, and supports optional persistence via shared_preferences.
AI-written summary of version 3.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want simple global state management without complex boilerplate
- You need to access and update state outside of a BuildContext
- You want optional automatic persistence to shared preferences
Skip it when
- Your project requires a strictly scoped, non-global state architecture
- You prefer stream-based or reactive state management solutions like BLoC
Strengths
- Works anywhere in Dart code even without a BuildContext
- Only rebuilds widgets that subscribe to updates using .of(context)
- Built-in support for persisting values using shared_preferences
Weaknesses
- Relies on global variables which can make testing harder
- Very limited documentation and changelog history
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
Wrap your root app widget with SharedValue.wrapApp().
final SharedValue<int> counter = SharedValue(
value: 0,
);
void main() {
runApp(
SharedValue.wrapApp(
MyApp(),
),
);
}Alternatives
Packages that do the same job and could replace shared_value.
- yx_state
A state management library for Dart and Flutter applications.
82Compare - cached_query
Library for caching, background fetching, and managing server state in Dart and Flutter.
90Compare - get
All-in-one framework for reactive state management, context-less routing, and dependency injection.
81Compare - context_watch
Observe value changes within the build method using extensions.
63Compare
Works with
Packages commonly used together with shared_value: ones it builds on, ones built on it, and its own family.