import 'package:shared_preferences/shared_preferences.dart';

class StorageService {
  StorageService._(this._prefs);
  final SharedPreferences _prefs;
  static StorageService? _instance;
  static StorageService get to => _instance!;

  static Future<StorageService> get instance async {
    if (_instance != null) return _instance!;
    final prefs = await SharedPreferences.getInstance();
    _instance = StorageService._(prefs);
    return _instance!;
  }

  bool getBool(String key, {bool def = false}) => _prefs.getBool(key) ?? def;
  Future<void> setBool(String key, bool v) => _prefs.setBool(key, v);
  String? getString(String key) => _prefs.getString(key);
  Future<void> setString(String key, String v) => _prefs.setString(key, v);
}
