import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; class ProfileController extends GetxController { static ProfileController get to => Get.find(); final _userName = ''.obs; final _email = ''.obs; final _avatar = ''.obs; final _isEditing = false.obs; final _storage = GetStorage(); String get userName => _userName.value; String get email => _email.value; String get avatar => _avatar.value; bool get isEditing => _isEditing.value; @override void onInit() { super.onInit(); loadUserData(); } void loadUserData() { try { _userName.value = _storage.read('userName') ?? 'User Name'; _email.value = _storage.read('userEmail') ?? 'user@example.com'; _avatar.value = _storage.read('userAvatar') ?? ''; } catch (e) { Get.snackbar('Error', 'Failed to load user data'); } } Future updateUserData({ String? userName, String? email, String? avatar, }) async { try { if (userName != null) { await _storage.write('userName', userName); _userName.value = userName; } if (email != null) { await _storage.write('userEmail', email); _email.value = email; } if (avatar != null) { await _storage.write('userAvatar', avatar); _avatar.value = avatar; } Get.snackbar('Success', 'Profile updated successfully'); } catch (e) { Get.snackbar('Error', 'Failed to update profile'); } } void toggleEditing() { _isEditing.value = !_isEditing.value; } }