feat : change role navigation
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/cupertino.dart' hide Image;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_chicken/data/common/fa_user_role.dart';
|
||||
import 'package:rasadyar_chicken/data/di/chicken_di.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';
|
||||
@@ -71,6 +72,8 @@ class ProfilePage extends GetView<ProfileLogic> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 16,
|
||||
children: [
|
||||
rolesWidget(),
|
||||
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 10),
|
||||
@@ -637,4 +640,40 @@ class ProfilePage extends GetView<ProfileLogic> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget rolesWidget() {
|
||||
return ObxValue((data) {
|
||||
if (data.value.status == ResourceStatus.loading) {
|
||||
return CupertinoActivityIndicator();
|
||||
} else if (data.value.status == ResourceStatus.error) {
|
||||
return ErrorWidget('خطا در دریافت اطلاعات کاربر');
|
||||
} else if (data.value.status == ResourceStatus.success) {
|
||||
List<String>? item = data.value.data?.roles;
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: EdgeInsets.symmetric(horizontal: 18.w),
|
||||
physics: BouncingScrollPhysics(),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 8.w,
|
||||
children: List.generate(item?.length ?? 0, (index) {
|
||||
Map tmpRole = getFaUserRoleWithOnTap(item?[index]);
|
||||
return CustomChip(
|
||||
isSelected:
|
||||
controller.gService.getSelectedRole(Module.chicken) == tmpRole.values.first,
|
||||
title: tmpRole.keys.first,
|
||||
index: index,
|
||||
onTap: (int p1) {
|
||||
controller.changeUserRole(tmpRole.values.first);
|
||||
|
||||
},
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
}, controller.userLocal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:rasadyar_chicken/presentation/routes/pages.dart';
|
||||
import 'package:rasadyar_chicken/presentation/routes/routes.dart';
|
||||
import 'package:rasadyar_chicken/presentation/utils/nested_keys_utils.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
import 'logic.dart';
|
||||
@@ -43,32 +44,8 @@ class PoultryScienceRootPage extends GetView<PoultryScienceRootLogic> {
|
||||
backgroundColor: AppColor.bgLight,
|
||||
body: IndexedStack(
|
||||
children: [
|
||||
/* Navigator(
|
||||
key: Get.nestedKey(0),
|
||||
onGenerateRoute: (settings) {
|
||||
final page = ChickenPages.pages.firstWhere(
|
||||
(e) => e.name == settings.name,
|
||||
orElse: () =>
|
||||
ChickenPages.pages.firstWhere((e) => e.name == ChickenRoutes.buySteward),
|
||||
);
|
||||
|
||||
return buildRouteFromGetPage(page);
|
||||
},
|
||||
),
|
||||
Navigator(
|
||||
key: Get.nestedKey(1),
|
||||
onGenerateRoute: (settings) {
|
||||
final page = ChickenPages.pages.firstWhere(
|
||||
(e) => e.name == settings.name,
|
||||
orElse: () =>
|
||||
ChickenPages.pages.firstWhere((e) => e.name == ChickenRoutes.saleSteward),
|
||||
);
|
||||
|
||||
return buildRouteFromGetPage(page);
|
||||
},
|
||||
),*/
|
||||
Navigator(
|
||||
key: Get.nestedKey(0),
|
||||
key: Get.nestedKey(poultryFirstKey),
|
||||
onGenerateRoute: (settings) {
|
||||
final page = ChickenPages.pages.firstWhere(
|
||||
(e) => e.name == settings.name,
|
||||
@@ -81,11 +58,11 @@ class PoultryScienceRootPage extends GetView<PoultryScienceRootLogic> {
|
||||
},
|
||||
),
|
||||
Navigator(
|
||||
key: Get.nestedKey(1),
|
||||
key: Get.nestedKey(poultrySecondKey),
|
||||
onGenerateRoute: (settings) => GetPageRoute(page: () => controller.pages[1]),
|
||||
),
|
||||
Navigator(
|
||||
key: Get.nestedKey(2),
|
||||
key: Get.nestedKey(poultryThirdKey),
|
||||
onGenerateRoute: (settings) => GetPageRoute(page: () => controller.pages[2]),
|
||||
),
|
||||
],
|
||||
@@ -100,7 +77,7 @@ class PoultryScienceRootPage extends GetView<PoultryScienceRootLogic> {
|
||||
icon: Assets.vec.settingSvg.path,
|
||||
isSelected: controller.currentPage.value == 0,
|
||||
onTap: () {
|
||||
Get.nestedKey(1)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(poultrySecondKey)?.currentState?.popUntil((route) => route.isFirst);
|
||||
|
||||
controller.changePage(0);
|
||||
},
|
||||
@@ -110,8 +87,8 @@ class PoultryScienceRootPage extends GetView<PoultryScienceRootLogic> {
|
||||
icon: Assets.vec.homeSvg.path,
|
||||
isSelected: controller.currentPage.value == 1,
|
||||
onTap: () {
|
||||
Get.nestedKey(0)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(2)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(poultryFirstKey)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(poultryThirdKey)?.currentState?.popUntil((route) => route.isFirst);
|
||||
controller.changePage(1);
|
||||
},
|
||||
),
|
||||
@@ -120,9 +97,8 @@ class PoultryScienceRootPage extends GetView<PoultryScienceRootLogic> {
|
||||
icon: Assets.vec.profileCircleSvg.path,
|
||||
isSelected: controller.currentPage.value == 2,
|
||||
onTap: () {
|
||||
/* Get.nestedKey(1)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(0)?.currentState?.popUntil((route) => route.isFirst);
|
||||
*/
|
||||
Get.nestedKey(poultryFirstKey)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(poultrySecondKey)?.currentState?.popUntil((route) => route.isFirst);
|
||||
controller.changePage(2);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:rasadyar_chicken/chicken.dart';
|
||||
import 'package:rasadyar_chicken/data/models/response/kill_house_distribution_info/kill_house_distribution_info.dart';
|
||||
import 'package:rasadyar_chicken/presentation/pages/steward/root/logic.dart';
|
||||
import 'package:rasadyar_chicken/presentation/utils/nested_keys_utils.dart';
|
||||
import 'package:rasadyar_core/core.dart' hide LinearGradient;
|
||||
|
||||
class StewardRootPage extends GetView<StewardRootLogic> {
|
||||
@@ -43,7 +44,7 @@ class StewardRootPage extends GetView<StewardRootLogic> {
|
||||
body: IndexedStack(
|
||||
children: [
|
||||
Navigator(
|
||||
key: Get.nestedKey(0),
|
||||
key: Get.nestedKey(stewardFirstKey),
|
||||
onGenerateRoute: (settings) {
|
||||
final page = ChickenPages.pages.firstWhere(
|
||||
(e) => e.name == settings.name,
|
||||
@@ -54,7 +55,7 @@ class StewardRootPage extends GetView<StewardRootLogic> {
|
||||
},
|
||||
),
|
||||
Navigator(
|
||||
key: Get.nestedKey(1),
|
||||
key: Get.nestedKey(stewardSecondKey),
|
||||
onGenerateRoute: (settings) {
|
||||
final page = ChickenPages.pages.firstWhere(
|
||||
(e) => e.name == settings.name,
|
||||
@@ -66,15 +67,15 @@ class StewardRootPage extends GetView<StewardRootLogic> {
|
||||
},
|
||||
),
|
||||
Navigator(
|
||||
key: Get.nestedKey(2),
|
||||
key: Get.nestedKey(stewardThirdKey),
|
||||
onGenerateRoute: (settings) => GetPageRoute(page: () => controller.pages[2]),
|
||||
),
|
||||
Navigator(
|
||||
key: Get.nestedKey(3),
|
||||
key: Get.nestedKey(stewardFourthKey),
|
||||
onGenerateRoute: (settings) => GetPageRoute(page: () => controller.pages[3]),
|
||||
),
|
||||
Navigator(
|
||||
key: Get.nestedKey(4),
|
||||
key: Get.nestedKey(stewardFifthKey),
|
||||
onGenerateRoute: (settings) => GetPageRoute(page: () => controller.pages[4]),
|
||||
),
|
||||
],
|
||||
@@ -88,7 +89,7 @@ class StewardRootPage extends GetView<StewardRootLogic> {
|
||||
icon: Assets.vec.buySvg.path,
|
||||
isSelected: controller.currentPage.value == 0,
|
||||
onTap: () {
|
||||
Get.nestedKey(1)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(stewardSecondKey)?.currentState?.popUntil((route) => route.isFirst);
|
||||
|
||||
controller.changePage(0);
|
||||
},
|
||||
@@ -98,7 +99,7 @@ class StewardRootPage extends GetView<StewardRootLogic> {
|
||||
icon: Assets.vec.saleSvg.path,
|
||||
isSelected: controller.currentPage.value == 1,
|
||||
onTap: () {
|
||||
Get.nestedKey(0)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(stewardFirstKey)?.currentState?.popUntil((route) => route.isFirst);
|
||||
controller.changePage(1);
|
||||
},
|
||||
),
|
||||
@@ -107,8 +108,8 @@ class StewardRootPage extends GetView<StewardRootLogic> {
|
||||
icon: Assets.vec.homeSvg.path,
|
||||
isSelected: controller.currentPage.value == 2,
|
||||
onTap: () {
|
||||
Get.nestedKey(1)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(0)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(stewardSecondKey)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(stewardFirstKey)?.currentState?.popUntil((route) => route.isFirst);
|
||||
controller.changePage(2);
|
||||
},
|
||||
),
|
||||
@@ -117,8 +118,8 @@ class StewardRootPage extends GetView<StewardRootLogic> {
|
||||
icon: Assets.vec.convertCubeSvg.path,
|
||||
isSelected: controller.currentPage.value == 3,
|
||||
onTap: () {
|
||||
Get.nestedKey(1)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(0)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(stewardSecondKey)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(stewardFirstKey)?.currentState?.popUntil((route) => route.isFirst);
|
||||
controller.changePage(3);
|
||||
},
|
||||
),
|
||||
@@ -127,8 +128,8 @@ class StewardRootPage extends GetView<StewardRootLogic> {
|
||||
icon: Assets.vec.profileCircleSvg.path,
|
||||
isSelected: controller.currentPage.value == 4,
|
||||
onTap: () {
|
||||
Get.nestedKey(1)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(0)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(stewardSecondKey)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(stewardFirstKey)?.currentState?.popUntil((route) => route.isFirst);
|
||||
|
||||
controller.changePage(4);
|
||||
},
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//region Steward Keys
|
||||
const int stewardFirstKey = 100;
|
||||
const int stewardSecondKey = 101;
|
||||
const int stewardThirdKey = 102;
|
||||
const int stewardFourthKey = 103;
|
||||
const int stewardFifthKey = 104;
|
||||
//endregion
|
||||
|
||||
//region poultry Keys
|
||||
const int poultryFirstKey = 105;
|
||||
const int poultrySecondKey = 106;
|
||||
const int poultryThirdKey = 107;
|
||||
//endregion
|
||||
@@ -55,6 +55,12 @@ class GService extends GetxService {
|
||||
}
|
||||
}
|
||||
|
||||
String? getSelectedRole(Module module) {
|
||||
TargetPage? targetPage = getTargetPage(module);
|
||||
|
||||
return targetPage?.route;
|
||||
}
|
||||
|
||||
Future<void> setIsNotFirstTime() async {
|
||||
AppModel model = AppModel(isFirstRun: false);
|
||||
|
||||
|
||||
@@ -30,18 +30,16 @@ class CustomChip extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? selectedColor : unSelectedColor,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border:
|
||||
isSelected
|
||||
? Border.fromBorderSide(BorderSide.none)
|
||||
: Border.all(width: 0.25, color: const Color(0xFFB0B0B0)),
|
||||
border: isSelected
|
||||
? Border.fromBorderSide(BorderSide.none)
|
||||
: Border.all(width: 1, color: AppColor.blueNormal),
|
||||
),
|
||||
child: Text(
|
||||
title,
|
||||
textAlign: TextAlign.center,
|
||||
style:
|
||||
isSelected
|
||||
? AppFonts.yekan10.copyWith(color: AppColor.whiteLight)
|
||||
: AppFonts.yekan10,
|
||||
style: isSelected
|
||||
? AppFonts.yekan14Bold.copyWith(color: AppColor.whiteLight)
|
||||
: AppFonts.yekan14Bold.copyWith(color: AppColor.blueNormal),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -103,7 +101,7 @@ class RFilterChips extends StatelessWidget {
|
||||
showCheckmark: false,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8.0)),
|
||||
side: BorderSide(width: 1, color: isSelected? selectedColor :unSelectedColor),
|
||||
side: BorderSide(width: 1, color: isSelected ? selectedColor : unSelectedColor),
|
||||
),
|
||||
deleteIcon: Icon(CupertinoIcons.clear_circled),
|
||||
onDeleted: isSelected ? () => onTap(index) : null,
|
||||
|
||||
Reference in New Issue
Block a user