Files
syncrow-app/lib/local/cache_helper.dart
Mohammad Salameh 84e142a099 initial commit
2024-02-14 10:58:43 +03:00

32 lines
825 B
Dart

import 'package:shared_preferences/shared_preferences.dart';
class CacheHelper {
static late SharedPreferences sharedPreferences;
static init() async {
sharedPreferences = await SharedPreferences.getInstance();
}
static Object? getData({
required String key,
}) async {
return sharedPreferences.get(key);
}
static Future setData({
required String key,
required value,
}) async {
if (value is String) return await sharedPreferences.setString(key, value);
if (value is int) return await sharedPreferences.setInt(key, value);
if (value is bool) return await sharedPreferences.setBool(key, value);
return await sharedPreferences.setDouble(key, value);
}
static dynamic removeData({
required String key,
}) async {
return sharedPreferences.remove(key);
}
}