initial commit: push everything
This commit is contained in:
36
lib/controllers/profile_controller.dart
Normal file
36
lib/controllers/profile_controller.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user