shared_pref_pro 1.1.1
shared_pref_pro: ^1.1.1 copied to clipboard
A clean, extensible, and production-ready local storage plugin with Smart Expiring Cache support. Works on Android, iOS, Web, Windows, macOS, and Linux.
shared_pref_pro #
A clean, extensible, and production-ready local storage plugin for Flutter. Supports Android, iOS, Web, Windows, macOS, and Linux.
Features #
- Simple API: Easy-to-use singleton
SharedPrefPro.instance. - Smart Expiring Cache: Save data with a TTL (Time To Live).
- Generic Support:
save<T>andget<T>for type safety. - Data Types: Supports
String,int,double,bool,List<String>. - JSON Objects: Automatic serialization for
Map<String, dynamic>andList<dynamic>. - Cross-Platform: Consistent behavior across 6 platforms.
- Thread-Safe: Native persistence on all platforms.
Getting Started #
Add shared_pref_pro to your pubspec.yaml:
dependencies:
shared_pref_pro: ^1.1.1
Usage #
Basic Usage #
import 'package:shared_pref_pro/shared_pref_pro.dart';
final sharedPref = SharedPrefPro.instance;
// Save a value
await sharedPref.save('username', 'john_doe');
// Get a value
String? username = await sharedPref.get<String>('username');
Smart Expiring Cache (New! 🚀) #
You can save values that automatically "expire" after a certain duration. This is perfect for tokens, OTPs, or temporary session data.
// Save a token that expires in 2 hours
await sharedPref.save(
'auth_token',
'secret_token_123',
expireIn: Duration(hours: 2),
);
// After 2 hours, this will return null and automatically delete the key from storage
String? token = await sharedPref.get<String>('auth_token');
Complex Objects (JSON) #
Map<String, dynamic> user = {'id': 1, 'name': 'John'};
// Save Map
await sharedPref.save('user_data', user);
// Get Map
Map<String, dynamic>? storedUser = await sharedPref.get<Map<String, dynamic>>('user_data');
Platform Support #
| Platform | Support | Storage Engine |
|---|---|---|
| Android | ✅ Yes | SharedPreferences |
| iOS | ✅ Yes | UserDefaults |
| Web | ✅ Yes | localStorage |
| Windows | ✅ Yes | MethodChannel / Native |
| macOS | ✅ Yes | MethodChannel / Native |
| Linux | ✅ Yes | MethodChannel / Native |
License #
MIT