import 'dart:convert'; import 'package:dietary_guard/models/alert_configuration.dart'; import 'package:get/get.dart'; import 'package:shared_preferences/shared_preferences.dart'; class AlertController extends GetxController { List configuration = List.empty(); late final SharedPreferences _prefs; @override void onInit() async { _prefs = await SharedPreferences.getInstance(); loadAlertConfiguration(); super.onInit(); } void loadAlertConfiguration() { final raw = _prefs.getString("alert_configuration"); if (raw == null) return; configuration = List.from(jsonDecode(raw).map( (x) => AlertConfiguration.fromJson(x), )); } Future setAlertConfiguration(List value) async { await _prefs.setString( "alert_configuration", jsonEncode(value.map((x) => x.toJson()).toList()), ); loadAlertConfiguration(); } void clearAlertConfiguration() { _prefs.remove("alert_configuration"); } }