import 'package:shared_preferences/shared_preferences.dart';

/// A class to handle shared preferences
class SharedPrefs {
  late final SharedPreferences _sharedPrefs;

  static final SharedPrefs _instance = SharedPrefs._internal();
  factory SharedPrefs() => _instance;
  SharedPrefs._internal();
  Future<void> init() async {
    _sharedPrefs = await SharedPreferences.getInstance();
  }

  setValue(String key, dynamic value) {
    if (value is bool) {
      _sharedPrefs.setBool(key, value);
    } else if (value is int) {
      _sharedPrefs.setInt(key, value);
    } else if (value is double) {
      _sharedPrefs.setDouble(key, value);
    } else if (value is String) {
      _sharedPrefs.setString(key, value);
    } else if (value is List<String>) {
      _sharedPrefs.setStringList(key, value);
    }
  }

  dynamic getValue(String key) {
    return _sharedPrefs.get(key);
  }
}
