import 'dart:convert'; import 'package:QuickSSH/classes/ServerCommand.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; class SecureStorageService { static const _storage = FlutterSecureStorage(); static const _key = 'mc_commands_list'; // SAVE: Converts list to JSON, then encrypts and stores it static Future saveCommands(List commands) async { final String jsonData = jsonEncode(commands.map((c) => c.toMap()).toList()); await _storage.write(key: _key, value: jsonData); } // LOAD: Decrypts data, then converts JSON back to Objects static Future> loadCommands() async { final String? encryptedData = await _storage.read(key: _key); if (encryptedData == null) return []; final List decodedData = jsonDecode(encryptedData); return decodedData.map((item) => ServerCommand.fromMap(item)).toList(); } }