sp_util
2.0.3, released 6 years ago by an unverified publisher
Flutter shared_preferences plugin utility supporting default values and objects.
WASM-readyUnverified publisher
What it does
It wraps the shared_preferences plugin to make it easier to store and retrieve primitive data types, objects, and object lists. It provides helper methods for key management, defaults, and saving custom serializable objects.
AI-written summary of version 2.0.3, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want a simpler utility wrapper around shared_preferences
- You need to easily serialize and store custom objects or lists of objects into key-value storage
Skip it when
- You require secure encrypted local storage
- You need complex relational queries or high-performance local databases
Strengths
- Simplifies working with shared_preferences
- Supports saving and retrieving custom objects and object lists directly
Weaknesses
- Relies on global static initialization which may require careful app startup flow
- Shared preferences is not suitable for large or secure datasets
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 2
Must call await SpUtil.getInstance() before running the app.
void main() async {
await SpUtil.getInstance();
SpUtil.putString("username", "sky24");
String userName = SpUtil.getString("username", defValue: "");
}Alternatives
Packages that do the same job and could replace sp_util.
Works with
Packages commonly used together with sp_util: ones it builds on, ones built on it, and its own family.
- shared_preferencessp_util depends on itFlutter plugin for reading and writing simple key-value pairs. Wraps NSUserDefaults on iOS and SharedPreferences on Android.
- synchronizedsp_util depends on itLock mechanism to prevent concurrent access to asynchronous code.
- flustarsBuilt on sp_utilFlutter common utilities for SharedPreferences, screen adaptation, directories, and widgets.
- flustars_flutter3Built on sp_utilA collection of utility classes for SharedPreferences, screen adaptation, widgets, and directories.