import 'package:shared_preferences/shared_preferences.dart'; enum StorageServiceValueType { string, stringList, boolean, } class StorageService { StorageService._(); static late SharedPreferences _preferences; static Future init() async { _preferences = await SharedPreferences.getInstance(); } static T? getValue( StorageServiceValueType valueType, String key ){ Map 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 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 removeValue( String key ) async { return await _preferences.remove(key); } }