feat : change role navigation

This commit is contained in:
2025-09-13 16:18:30 +03:30
parent 29059cb7b1
commit 7f29023e94
7 changed files with 110 additions and 56 deletions

View File

@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_chicken/data/models/request/change_password/change_password_request_model.dart';
import 'package:rasadyar_chicken/data/models/response/iran_province_city/iran_province_city_model.dart';
import 'package:rasadyar_chicken/data/models/response/user_profile/user_profile.dart';
@@ -9,10 +8,12 @@ import 'package:rasadyar_core/core.dart';
class ProfileLogic extends GetxController {
StewardRootLogic rootLogic = Get.find<StewardRootLogic>();
GService gService = Get.find<GService>();
TokenStorageService tokenService = Get.find<TokenStorageService>();
RxInt selectedInformationType = 0.obs;
Rxn<Jalali> birthDate = Rxn<Jalali>();
Rx<Resource<UserProfile>> userProfile = Rx<Resource<UserProfile>>(Resource.loading());
Rx<Resource<UserLocalModel>> userLocal = Rx<Resource<UserLocalModel>>(Resource.loading());
TextEditingController nameController = TextEditingController();
TextEditingController lastNameController = TextEditingController();
@@ -48,6 +49,7 @@ class ProfileLogic extends GetxController {
void onReady() {
super.onReady();
getUserProfile();
getUserRole();
selectedProvince.listen((p0) => getCites());
userProfile.listen((data) {
nameController.text = data.data?.firstName ?? '';
@@ -142,9 +144,28 @@ class ProfileLogic extends GetxController {
}
}
Future<void> getUserRole() async {
userLocal.value = Resource.loading();
await safeCall<UserLocalModel?>(
call: () async => rootLogic.tokenService.getUserLocal(Module.chicken),
onSuccess: (result) {
if (result != null) {
userLocal.value = Resource.success(result);
}
},
onError: (error, stackTrace) {},
);
}
void clearPasswordForm() {
oldPasswordController.clear();
newPasswordController.clear();
retryNewPasswordController.clear();
}
Future<void> changeUserRole(String newRole) async {
await gService.saveSelectedRole(Module.chicken, newRole);
Get.offAllNamed(newRole);
}
}