initial commit

This commit is contained in:
2025-11-28 23:58:41 +03:00
commit 013690061c
77 changed files with 2337 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
import 'package:shared_preferences/shared_preferences.dart';
enum StorageServiceValueType {
string,
stringList,
boolean,
}
class StorageService {
StorageService._();
static late SharedPreferences _preferences;
static Future<void> init() async {
_preferences = await SharedPreferences.getInstance();
}
static T? getValue<T>( StorageServiceValueType valueType, String key ){
Map<StorageServiceValueType, Function( String key ) > data = {
StorageServiceValueType.string: _preferences.getString,
StorageServiceValueType.stringList: _preferences.getStringList,
StorageServiceValueType.boolean: _preferences.getBool,
};
final Function( String key )? function = data[valueType];
if( function == null ) throw Exception('Unimplemented value type');
return function(key) as T?;
}
static Future<bool> setValue( StorageServiceValueType valueType, String key, dynamic value ) async {
switch( valueType ) {
case .string:
return _preferences.setString(key, value);
case.stringList:
return _preferences.setStringList(key, value);
case .boolean:
return _preferences.setBool(key, value);
}
throw Exception('Unimplemented value type');
}
static Future<bool> removeValue( String key ) async {
return await _preferences.remove(key);
}
}