diff --git a/packages/chicken/lib/features/common/presentation/page/auth/logic.dart b/packages/chicken/lib/features/common/presentation/page/auth/logic.dart index c1a3286..6b1e8b5 100644 --- a/packages/chicken/lib/features/common/presentation/page/auth/logic.dart +++ b/packages/chicken/lib/features/common/presentation/page/auth/logic.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:rasadyar_chicken/data/common/dio_error_handler.dart'; +import 'package:rasadyar_chicken/data/common/fa_user_role.dart'; import 'package:rasadyar_chicken/data/di/chicken_di.dart'; import 'package:rasadyar_chicken/features/common/data/model/response/user_info/user_info_model.dart'; import 'package:rasadyar_chicken/features/common/data/model/response/user_profile_model/user_profile_model.dart'; @@ -123,7 +124,6 @@ class AuthLogic extends GetxController with GetTickerProviderStateMixin { }, ), onSuccess: (result) async { - var tmpRoles = result?.role?.where((element) { final allowedRoles = { 'poultryscience', @@ -141,9 +141,9 @@ class AuthLogic extends GetxController with GetTickerProviderStateMixin { final lowerElement = element.toString().toLowerCase().trim(); return allowedRoles.contains(lowerElement); }).toList(); - - if (tmpRoles != null && tmpRoles.isNotEmpty ) { - await gService.saveSelectedModule(_module); + + if (tmpRoles != null && tmpRoles.isNotEmpty) { + await gService.saveSelectedModule(_module); await tokenStorageService.saveModule(_module); await tokenStorageService.saveAccessToken( _module, @@ -169,8 +169,19 @@ class AuthLogic extends GetxController with GetTickerProviderStateMixin { "device_name": deviceName.value, }, ); + if (tmpRoles.length == 1) { + var tmpRoute = getFaUserRoleWithOnTap(tmpRoles.first).values.first; - Get.offAndToNamed(CommonRoutes.role); + await gService.saveRole(Module.chicken, tmpRoles.first); + await gService.saveRoute( + Module.chicken, + tmpRoute ?? CommonRoutes.role, + ); + + Get.offAndToNamed(tmpRoute ?? CommonRoutes.role); + } else { + Get.offAndToNamed(CommonRoutes.role); + } } else { Get.snackbar( 'با احترام ', diff --git a/packages/chicken/lib/features/common/presentation/page/profile/view.dart b/packages/chicken/lib/features/common/presentation/page/profile/view.dart index 3b3f635..481f252 100644 --- a/packages/chicken/lib/features/common/presentation/page/profile/view.dart +++ b/packages/chicken/lib/features/common/presentation/page/profile/view.dart @@ -32,7 +32,11 @@ class ProfilePage extends GetView { return Container( width: 128.w, height: 128.h, - child: Center(child: CupertinoActivityIndicator(color: AppColor.greenNormal)), + child: Center( + child: CupertinoActivityIndicator( + color: AppColor.greenNormal, + ), + ), ); } @@ -57,7 +61,9 @@ class ProfilePage extends GetView { child: data.value.data?.image != null ? CircleAvatar( radius: 64.w, - backgroundImage: NetworkImage(data.value.data!.image!), + backgroundImage: NetworkImage( + data.value.data!.image!, + ), ) : Icon(Icons.person, size: 64.w), ), @@ -129,16 +135,25 @@ class ProfilePage extends GetView { }, controller.userProfile), GestureDetector( onTap: () { - Get.bottomSheet(changePasswordBottomSheet(), isScrollControlled: true); + Get.bottomSheet( + changePasswordBottomSheet(), + isScrollControlled: true, + ); }, child: Container( height: 47.h, margin: EdgeInsets.symmetric(horizontal: 8, vertical: 8.h), - padding: EdgeInsets.symmetric(horizontal: 11.h, vertical: 8.h), + padding: EdgeInsets.symmetric( + horizontal: 11.h, + vertical: 8.h, + ), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(8), - border: Border.all(width: 1, color: const Color(0xFFD6D6D6)), + border: Border.all( + width: 1, + color: const Color(0xFFD6D6D6), + ), ), child: Row( spacing: 6, @@ -146,12 +161,17 @@ class ProfilePage extends GetView { Assets.vec.lockSvg.svg( width: 24.w, height: 24.h, - colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn), + colorFilter: ColorFilter.mode( + AppColor.blueNormal, + BlendMode.srcIn, + ), ), Text( 'تغییر رمز عبور', textAlign: TextAlign.center, - style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal), + style: AppFonts.yekan14.copyWith( + color: AppColor.blueNormal, + ), ), ], ), @@ -159,16 +179,25 @@ class ProfilePage extends GetView { ), GestureDetector( onTap: () { - Get.bottomSheet(exitBottomSheet(), isScrollControlled: true); + Get.bottomSheet( + exitBottomSheet(), + isScrollControlled: true, + ); }, child: Container( height: 47.h, margin: EdgeInsets.symmetric(horizontal: 8), - padding: EdgeInsets.symmetric(horizontal: 11.h, vertical: 8.h), + padding: EdgeInsets.symmetric( + horizontal: 11.h, + vertical: 8.h, + ), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(8), - border: Border.all(width: 1, color: const Color(0xFFD6D6D6)), + border: Border.all( + width: 1, + color: const Color(0xFFD6D6D6), + ), ), child: Row( spacing: 6, @@ -176,12 +205,17 @@ class ProfilePage extends GetView { Assets.vec.logoutSvg.svg( width: 24.w, height: 24.h, - colorFilter: ColorFilter.mode(AppColor.redNormal, BlendMode.srcIn), + colorFilter: ColorFilter.mode( + AppColor.redNormal, + BlendMode.srcIn, + ), ), Text( 'خروج', textAlign: TextAlign.center, - style: AppFonts.yekan14.copyWith(color: AppColor.redNormal), + style: AppFonts.yekan14.copyWith( + color: AppColor.redNormal, + ), ), ], ), @@ -219,7 +253,10 @@ class ProfilePage extends GetView { child: ObxValue( (val) => Container( height: val.value ? 320.h : 47.h, - margin: EdgeInsets.symmetric(horizontal: 8, vertical: val.value ? 8 : 0), + margin: EdgeInsets.symmetric( + horizontal: 8, + vertical: val.value ? 8 : 0, + ), padding: EdgeInsets.symmetric(horizontal: 11.h, vertical: 8.h), decoration: BoxDecoration( color: Colors.white, @@ -244,14 +281,20 @@ class ProfilePage extends GetView { child: Assets.vec.editSvg.svg( width: 24.w, height: 24.h, - colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn), + colorFilter: ColorFilter.mode( + AppColor.blueNormal, + BlendMode.srcIn, + ), ), ), ], ), Padding( - padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0), + padding: const EdgeInsets.symmetric( + horizontal: 12.0, + vertical: 8.0, + ), child: Column( children: [ itemList( @@ -278,7 +321,10 @@ class ProfilePage extends GetView { ), itemList( title: 'تاریخ تولد', - content: item.birthday?.toJalali.formatCompactDate() ?? 'نامشخص', + content: + item.birthday?.toJalali + .formatCompactDate() ?? + 'نامشخص', icon: Assets.vec.calendarSvg.path, ), //todo @@ -299,7 +345,12 @@ class ProfilePage extends GetView { ) : Row( mainAxisAlignment: MainAxisAlignment.end, - children: [Icon(CupertinoIcons.chevron_down, color: AppColor.iconColor)], + children: [ + Icon( + CupertinoIcons.chevron_down, + color: AppColor.iconColor, + ), + ], ), ), controller.isUserInformationOpen, @@ -340,7 +391,10 @@ class ProfilePage extends GetView { child: ObxValue( (val) => Container( height: val.value ? 320.h : 47.h, - margin: EdgeInsets.symmetric(horizontal: 8, vertical: val.value ? 12 : 0), + margin: EdgeInsets.symmetric( + horizontal: 8, + vertical: val.value ? 12 : 0, + ), padding: EdgeInsets.symmetric(horizontal: 11.h), decoration: BoxDecoration( color: Colors.white, @@ -365,14 +419,20 @@ class ProfilePage extends GetView { child: Assets.vec.editSvg.svg( width: 24.w, height: 24.h, - colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn), + colorFilter: ColorFilter.mode( + AppColor.blueNormal, + BlendMode.srcIn, + ), ), ), ], ), Padding( - padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0), + padding: const EdgeInsets.symmetric( + horizontal: 12.0, + vertical: 8.0, + ), child: Column( spacing: 2, children: [ @@ -389,7 +449,8 @@ class ProfilePage extends GetView { ), itemList( title: 'شماره ثبت', - content: item.unitRegistrationNumber ?? 'نامشخص', + content: + item.unitRegistrationNumber ?? 'نامشخص', visible: item.unitName != null, ), @@ -414,7 +475,10 @@ class ProfilePage extends GetView { content: item.city ?? 'نامشخص', visible: item.unitName != null, ), - itemList(title: 'آدرس', content: item.unitAddress ?? 'نامشخص'), + itemList( + title: 'آدرس', + content: item.unitAddress ?? 'نامشخص', + ), ], ), ), @@ -422,7 +486,12 @@ class ProfilePage extends GetView { ) : Row( mainAxisAlignment: MainAxisAlignment.end, - children: [Icon(CupertinoIcons.chevron_down, color: AppColor.iconColor)], + children: [ + Icon( + CupertinoIcons.chevron_down, + color: AppColor.iconColor, + ), + ], ), ), controller.isUnitInformationOpen, @@ -480,12 +549,21 @@ class ProfilePage extends GetView { child: SvgGenImage.vec(icon).svg( width: 20.w, height: 20.h, - colorFilter: ColorFilter.mode(AppColor.textColor, BlendMode.srcIn), + colorFilter: ColorFilter.mode( + AppColor.textColor, + BlendMode.srcIn, + ), ), ), - Text(title, style: AppFonts.yekan14.copyWith(color: AppColor.textColor)), + Text( + title, + style: AppFonts.yekan14.copyWith(color: AppColor.textColor), + ), Spacer(), - Text(content, style: AppFonts.yekan14.copyWith(color: AppColor.textColor)), + Text( + content, + style: AppFonts.yekan14.copyWith(color: AppColor.textColor), + ), ], ), ), @@ -512,7 +590,9 @@ class ProfilePage extends GetView { padding: EdgeInsets.all(6), decoration: ShapeDecoration( color: cardColor ?? AppColor.blueLight, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + ), ), child: Container( padding: EdgeInsets.all(4), @@ -523,7 +603,8 @@ class ProfilePage extends GetView { child: SvgGenImage.vec(icon).svg( width: 40.w, height: 40.h, - colorFilter: color ?? ColorFilter.mode(Colors.white, BlendMode.srcIn), + colorFilter: + color ?? ColorFilter.mode(Colors.white, BlendMode.srcIn), ), ), ), @@ -547,7 +628,9 @@ class ProfilePage extends GetView { children: [ Text( 'ویرایش اطلاعات هویتی', - style: AppFonts.yekan16Bold.copyWith(color: AppColor.darkGreyDarkHover), + style: AppFonts.yekan16Bold.copyWith( + color: AppColor.darkGreyDarkHover, + ), ), Container( @@ -619,7 +702,9 @@ class ProfilePage extends GetView { children: [ Text( 'عکس پروفایل', - style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal), + style: AppFonts.yekan16Bold.copyWith( + color: AppColor.blueNormal, + ), ), ObxValue((data) { return Container( @@ -628,17 +713,29 @@ class ProfilePage extends GetView { decoration: BoxDecoration( color: AppColor.lightGreyNormal, borderRadius: BorderRadius.circular(8), - border: Border.all(width: 1, color: AppColor.blackLight), + border: Border.all( + width: 1, + color: AppColor.blackLight, + ), ), child: Center( child: data.value == null ? Padding( - padding: const EdgeInsets.fromLTRB(30, 10, 10, 30), + padding: const EdgeInsets.fromLTRB( + 30, + 10, + 10, + 30, + ), child: Image.network( - controller.userProfile.value.data?.image ?? '', + controller.userProfile.value.data?.image ?? + '', ), ) - : Image.file(File(data.value!.path), fit: BoxFit.cover), + : Image.file( + File(data.value!.path), + fit: BoxFit.cover, + ), ), ); }, controller.selectedImage), @@ -651,14 +748,18 @@ class ProfilePage extends GetView { text: 'گالری', width: 150.w, height: 40.h, - textStyle: AppFonts.yekan20.copyWith(color: Colors.white), + textStyle: AppFonts.yekan20.copyWith( + color: Colors.white, + ), onPressed: () async { - controller.selectedImage.value = await controller.imagePicker.pickImage( - source: ImageSource.gallery, - imageQuality: 60, - maxWidth: 1080, - maxHeight: 720, - ); + controller.selectedImage.value = await controller + .imagePicker + .pickImage( + source: ImageSource.gallery, + imageQuality: 60, + maxWidth: 1080, + maxHeight: 720, + ); }, ), SizedBox(width: 16), @@ -666,14 +767,18 @@ class ProfilePage extends GetView { text: 'دوربین', width: 150.w, height: 40.h, - textStyle: AppFonts.yekan20.copyWith(color: AppColor.blueNormal), + textStyle: AppFonts.yekan20.copyWith( + color: AppColor.blueNormal, + ), onPressed: () async { - controller.selectedImage.value = await controller.imagePicker.pickImage( - source: ImageSource.camera, - imageQuality: 60, - maxWidth: 1080, - maxHeight: 720, - ); + controller.selectedImage.value = await controller + .imagePicker + .pickImage( + source: ImageSource.camera, + imageQuality: 60, + maxWidth: 1080, + maxHeight: 720, + ); }, ), ], @@ -724,7 +829,9 @@ class ProfilePage extends GetView { children: [ Text( 'تغییر رمز عبور', - style: AppFonts.yekan16Bold.copyWith(color: AppColor.darkGreyDarkHover), + style: AppFonts.yekan16Bold.copyWith( + color: AppColor.darkGreyDarkHover, + ), ), SizedBox(), RTextField( @@ -736,7 +843,8 @@ class ProfilePage extends GetView { validator: (value) { if (value == null || value.isEmpty) { return 'رمز عبور را وارد کنید'; - } else if (controller.userProfile.value.data?.password != value) { + } else if (controller.userProfile.value.data?.password != + value) { return 'رمز عبور صحیح نیست'; } return null; @@ -820,7 +928,10 @@ class ProfilePage extends GetView { child: Column( spacing: 8, children: [ - Text('خروج', style: AppFonts.yekan16Bold.copyWith(color: AppColor.error)), + Text( + 'خروج', + style: AppFonts.yekan16Bold.copyWith(color: AppColor.error), + ), SizedBox(), Text( 'آیا مطمئن هستید که می‌خواهید از حساب کاربری خود خارج شوید؟', @@ -840,7 +951,9 @@ class ProfilePage extends GetView { backgroundColor: AppColor.error, onPressed: () async { await Future.wait([ - controller.tokenService.deleteModuleTokens(Module.chicken), + controller.tokenService.deleteModuleTokens( + Module.chicken, + ), controller.gService.clearSelectedModule(), ]).then((value) async { await removeChickenDI(); @@ -877,17 +990,20 @@ class ProfilePage extends GetView { scrollDirection: Axis.horizontal, padding: EdgeInsets.symmetric(horizontal: 8.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.getRoute(Module.chicken) == tmpRole.values.first, + isSelected: + controller.gService.getRoute(Module.chicken) == + tmpRole.values.first, title: tmpRole.keys.first, index: index, onTap: (int p1) { + controller.changeUserRole(tmpRole.values.first); }, );