Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
981 B
2
Indexable
Never
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);
  }
}
Leave a Comment