Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:shared_preferences/shared_preferences.dart';
- class PreferenceManager {
- static const keyToken = "token";
- PreferenceManager._();
- static final PreferenceManager instance = PreferenceManager._();
- late final SharedPreferences _preference;
- Future<void> initialize() async {
- _preference = await SharedPreferences.getInstance();
- }
- String getString(String key, {String defaultValue = ""}) {
- return _preference.getString(key) ?? defaultValue;
- }
- void setString(String key, String value) {
- _preference.setString(key, value);
- }
- int getInt(String key, {int defaultValue = 0}) {
- return _preference.getInt(key) ?? defaultValue;
- }
- void setInt(String key, int value) {
- _preference.setInt(key, value);
- }
- double getDouble(String key, {double defaultValue = 0.0}) {
- return _preference.getDouble(key) ?? defaultValue;
- }
- void setDouble(String key, double value) {
- _preference.setDouble(key, value);
- }
- bool getBool(String key, {bool defaultValue = false}) {
- return _preference.getBool(key) ?? defaultValue;
- }
- void setBool(String key, bool value) {
- _preference.setBool(key, value);
- }
- List<String> getStringList(String key, {List<String> defaultValue = const []}) {
- return _preference.getStringList(key) ?? defaultValue;
- }
- void setStringList(String key, List<String> value) {
- _preference.setStringList(key, value);
- }
- void remove(String key) {
- _preference.remove(key);
- }
- void clear() {
- _preference.clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement