37 lines
1.3 KiB
Dart
37 lines
1.3 KiB
Dart
import 'dart:io';
|
|
import 'package:get/get.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class ProfileController extends GetxController {
|
|
final RxString imagePath = ''.obs;
|
|
final RxString userName = ''.obs;
|
|
final RxString userEmail = ''.obs;
|
|
final RxString userContact = ''.obs;
|
|
final RxString userAddress = ''.obs;
|
|
|
|
void setImagePath(String path) {
|
|
imagePath.value = path;
|
|
}
|
|
|
|
Future<void> loadFromPrefs() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
userName.value = (prefs.getString('user_name') ?? '').trim();
|
|
userEmail.value = (prefs.getString('user_email') ?? '').trim();
|
|
userContact.value = (prefs.getString('contactno') ?? '').trim();
|
|
userAddress.value = (prefs.getString('user_address') ?? '').trim();
|
|
}
|
|
|
|
void setProfile({String? name, String? email, String? contact, String? address}) {
|
|
if (name != null && name.trim().isNotEmpty) userName.value = name.trim();
|
|
if (email != null && email.trim().isNotEmpty) userEmail.value = email.trim();
|
|
if (contact != null && contact.trim().isNotEmpty) userContact.value = contact.trim();
|
|
if (address != null && address.trim().isNotEmpty) userAddress.value = address.trim();
|
|
}
|
|
|
|
File? get fileOrNull {
|
|
final path = imagePath.value;
|
|
if (path.isEmpty) return null;
|
|
return File(path);
|
|
}
|
|
}
|