import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; class GetStorageService extends GetxService { final GetStorage _box = GetStorage(); // CREATE / UPDATE Future save(String key, T value) async { await _box.write(key, value); } // READ T? get(String key) { return _box.read(key); } // READ mit Defaultwert T getOrDefault(String key, T defaultValue) { return get(key) ?? defaultValue; } // DELETE Future delete(String key) async { await _box.remove(key); } // EXISTS bool exists(String key) { return _box.hasData(key); } // CLEAR ALL Future clear() async { await _box.erase(); } // READ LIST List getList(String key) { final data = _box.read>(key); return data?.cast() ?? []; } // SAVE LIST Future saveList(String key, List items) async { await _box.write(key, items); } // ADD ITEM Future addItem(String key, T item) async { final items = getList(key); items.add(item); await saveList(key, items); } // UPDATE ITEM Future updateItem(String key, int index, T item) async { final items = getList(key); if (index < 0 || index >= items.length) { throw RangeError.index(index, items); } items[index] = item; await saveList(key, items); } // DELETE ITEM Future deleteItem(String key, int index) async { final items = getList(key); if (index < 0 || index >= items.length) { throw RangeError.index(index, items); } items.removeAt(index); await saveList(key, items); } Future saveModelList( String key, List> items, ) async { await _box.write(key, items); } List> getModelList(String key) { final data = _box.read>(key) ?? []; return data.map((item) => Map.from(item as Map)).toList(); } }