Untitled
unknown
plain_text
2 years ago
981 B
7
Indexable
import 'dart:async' show Future;
import 'package:shared_preferences/shared_preferences.dart';
class PreferenceUtils {
static Future<SharedPreferences> get _instance async =>
_prefsInstance ??= await SharedPreferences.getInstance();
static SharedPreferences? _prefsInstance;
static Future<SharedPreferences> init() async {
_prefsInstance = await _instance;
return _prefsInstance!;
}
static Future<String?> getString(String key) async {
var prefs = await _instance;
return prefs.getString(key);
}
static Future<bool> setString(String key, dynamic value) async {
var prefs = await _instance;
return prefs.setString(key, value);
}
static Future<bool?> getBool(String key) async {
var prefs = await _instance;
return prefs.getBool(key) ?? false;
}
static Future<bool> setBool(String key, bool value) async {
var prefs = await _instance;
return prefs.setBool(key, value);
}
}
Editor is loading...
Leave a Comment