shared_pref_pro 1.1.3
shared_pref_pro: ^1.1.3 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.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:shared_pref_pro/shared_pref_pro.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _sharedPref = SharedPrefPro.instance;
String _storedValue = 'None';
final _controller = TextEditingController();
@override
void initState() {
super.initState();
_loadValue();
}
Future<void> _loadValue() async {
final value = await _sharedPref.get<String>('test_key');
setState(() {
_storedValue = value ?? 'None';
});
}
Future<void> _saveValue() async {
await _sharedPref.save<String>('test_key', _controller.text);
_loadValue();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('SharedPrefPro Example')),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Text('Stored Value: $_storedValue'),
TextField(
controller: _controller,
decoration: const InputDecoration(labelText: 'Enter value'),
),
ElevatedButton(
onPressed: _saveValue,
child: const Text('Save'),
),
ElevatedButton(
onPressed: () async {
await _sharedPref.clear();
_loadValue();
},
child: const Text('Clear'),
),
],
),
),
),
);
}
}