import 'package:flutter_secure_storage/flutter_secure_storage.dart'; class StorageItem { StorageItem(this.key, this.value); final String key; final String value; } class StorageService { final _secureStorage = const FlutterSecureStorage( aOptions: AndroidOptions( encryptedSharedPreferences: true, ), ); Future writeData(StorageItem item) async { await _secureStorage.write( key: item.key, value: item.value, ); } Future readData(String key) async { return await _secureStorage.read(key: key); } Future> readAllSecureData() async { var allData = await _secureStorage.readAll(); List list = allData.entries.map((e) => StorageItem(e.key, e.value)).toList(); return list; } Future containsData(String key) async { return await _secureStorage.containsKey(key: key); } Future deleteSecureData(StorageItem item) async { await _secureStorage.delete( key: item.key, ); } Future deleteAllSecureData() async { await _secureStorage.deleteAll(); } Future setNotificationSetting(bool enabled) async { return await writeData(StorageItem('notifications', enabled ? '1' : '0')); } Future get notificationSetting async { final enabled = await readData('notifications') == '1' ? true : false; return enabled; } Future get accountLevel async { int? level; final lev = await readData('account_level'); if (lev != null) { level = int.tryParse(lev); } return level ?? 0; } Future setAccountLevel(int level) async { return await writeData(StorageItem('account_level', '$level')); } Future initAccountLevel() async { return await writeData(StorageItem('account_level', '0')); } Future addAccountLevel() async { int? level; final l = await readData('account_level'); if (l != null) { level = int.tryParse(l); } return await writeData( StorageItem('account_level', '${level != null ? level + 1 : 1}')); } }