From 1aa15e5dd65fadc72392b79a2edbd2098299942d Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Wed, 5 Feb 2025 17:01:03 +0400 Subject: [PATCH 1/3] fixed loading --- .../all_spaces/widgets/loaded_space_widget.dart | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/pages/spaces_management/all_spaces/widgets/loaded_space_widget.dart b/lib/pages/spaces_management/all_spaces/widgets/loaded_space_widget.dart index 0ce06c7c..d66970e6 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/loaded_space_widget.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/loaded_space_widget.dart @@ -42,20 +42,29 @@ class _LoadedSpaceViewState extends State { _spaceModels = List.from(widget.spaceModels ?? []); } + @override @override void didUpdateWidget(covariant LoadedSpaceView oldWidget) { super.didUpdateWidget(oldWidget); if (widget.spaceModels != oldWidget.spaceModels) { - setState(() { - _spaceModels = List.from(widget.spaceModels ?? []); + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted) { + setState(() { + _spaceModels = List.from(widget.spaceModels ?? []); + }); + } }); } } void _onSpaceModelsUpdated(List updatedModels) { if (mounted && updatedModels != _spaceModels) { - setState(() { - _spaceModels = updatedModels; + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted) { + setState(() { + _spaceModels = updatedModels; + }); + } }); } } From f6d66185b3c02fafd74db0d24bb3c4eb89e6fb8e Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Thu, 6 Feb 2025 00:18:44 +0400 Subject: [PATCH 2/3] updating tags inside subspace --- .../spaces_management/helper/tag_helper.dart | 59 ++++++++++++++++++- .../dialog/create_space_model_dialog.dart | 8 +-- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/lib/pages/spaces_management/helper/tag_helper.dart b/lib/pages/spaces_management/helper/tag_helper.dart index 9c0299ba..3e3353a3 100644 --- a/lib/pages/spaces_management/helper/tag_helper.dart +++ b/lib/pages/spaces_management/helper/tag_helper.dart @@ -299,7 +299,7 @@ class TagHelper { static Map updateSubspaceTagModels( List updatedTags, List? subspaces) { - return TagHelper.updateTags( + final result = TagHelper.updateTags( updatedTags: updatedTags, subspaces: subspaces, getInternalId: (tag) => tag.internalId, @@ -310,6 +310,34 @@ class TagHelper { setSubspaceTags: (subspace, tags) => subspace.tags = tags, checkTagExistInSubspace: checkTagExistInSubspaceModels, ); + + final processedTags = result['updatedTags'] as List; + final processedSubspaces = + List.from(result['subspaces'] as List); + + for (var subspace in processedSubspaces) { + final subspaceTags = subspace.tags; + + if (subspaceTags != null) { + for (int i = 0; i < subspaceTags.length; i++) { + final tag = subspaceTags[i]; + + // Find the updated tag inside processedTags + final changedTag = updatedTags.firstWhere( + (t) => t.internalId == tag.internalId, + orElse: () => tag, + ); + + if (changedTag.tag != tag.tag) { + subspaceTags[i] = changedTag.copyWith(tag: changedTag.tag); + } + } + } + + subspace.tags = subspaceTags; + } + + return {'updatedTags': processedTags, 'subspaces': processedSubspaces}; } static int? checkTagExistInSubspace(Tag tag, List? subspaces) { @@ -328,7 +356,7 @@ class TagHelper { static Map processTags( List updatedTags, List? subspaces) { - return TagHelper.updateTags( + final result = TagHelper.updateTags( updatedTags: updatedTags, subspaces: subspaces, getInternalId: (tag) => tag.internalId, @@ -339,6 +367,33 @@ class TagHelper { setSubspaceTags: (subspace, tags) => subspace.tags = tags, checkTagExistInSubspace: checkTagExistInSubspace, ); + + final processedTags = result['updatedTags'] as List; + final processedSubspaces = + List.from(result['subspaces'] as List); + + for (var subspace in processedSubspaces) { + final subspaceTags = subspace.tags; + + if (subspaceTags != null) { + for (int i = 0; i < subspaceTags.length; i++) { + final tag = subspaceTags[i]; + + final changedTag = updatedTags.firstWhere( + (t) => t.internalId == tag.internalId, + orElse: () => tag, + ); + + if (changedTag.tag != tag.tag) { + subspaceTags[i] = changedTag.copyWith(tag: changedTag.tag); + } + } + } + + subspace.tags = subspaceTags; + } + + return {'updatedTags': processedTags, 'subspaces': processedSubspaces}; } static List getAllTagValues( diff --git a/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart b/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart index 28b548b0..dd41903e 100644 --- a/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart +++ b/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart @@ -130,14 +130,14 @@ class CreateSpaceModelDialog extends StatelessWidget { SubspaceModelCreate( subspaces: state.space.subspaceModels ?? [], tags: state.space.tags ?? [], - onSpaceModelUpdate: (updatedSubspaces,updatedTags) { + onSpaceModelUpdate: (updatedSubspaces, updatedTags) { context .read() .add(AddSubspacesToSpaceTemplate(updatedSubspaces)); - if(updatedTags!=null){ + if (updatedTags != null) { context - .read() - .add(AddTagsToSpaceTemplate(updatedTags)); + .read() + .add(AddTagsToSpaceTemplate(updatedTags)); } }, ), From 98ad7090d8461594b7335b75fbff3f7bc765b518 Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Thu, 6 Feb 2025 01:01:21 +0300 Subject: [PATCH 3/3] Removed prints and unused code --- lib/pages/home/view/home_page_web.dart | 13 +- .../add_user_dialog/view/add_user_dialog.dart | 244 ++++++++---------- lib/services/user_permission.dart | 15 +- 3 files changed, 120 insertions(+), 152 deletions(-) diff --git a/lib/pages/home/view/home_page_web.dart b/lib/pages/home/view/home_page_web.dart index baf18fc2..aad4a3be 100644 --- a/lib/pages/home/view/home_page_web.dart +++ b/lib/pages/home/view/home_page_web.dart @@ -37,12 +37,9 @@ class _HomeWebPageState extends State { onPopInvoked: (didPop) => false, child: BlocConsumer( listener: (BuildContext context, state) { - print('state=$state'); if (state is HomeInitial) { - if (homeBloc.user!.hasAcceptedWebAgreement == false && - !_dialogShown) { - _dialogShown = - true; // Set the flag to true to indicate the dialog is showing. + if (homeBloc.user!.hasAcceptedWebAgreement == false && !_dialogShown) { + _dialogShown = true; // Set the flag to true to indicate the dialog is showing. Future.delayed(const Duration(seconds: 1), () { showDialog( context: context, @@ -101,8 +98,7 @@ class _HomeWebPageState extends State { width: size.width * 0.68, child: GridView.builder( itemCount: 3, // Change this count if needed. - gridDelegate: - const SliverGridDelegateWithFixedCrossAxisCount( + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 3, // Adjust as needed. crossAxisSpacing: 20.0, mainAxisSpacing: 20.0, @@ -114,8 +110,7 @@ class _HomeWebPageState extends State { active: homeBloc.homeItems[index].active!, name: homeBloc.homeItems[index].title!, img: homeBloc.homeItems[index].icon!, - onTap: () => - homeBloc.homeItems[index].onPress(context), + onTap: () => homeBloc.homeItems[index].onPress(context), ); }, ), diff --git a/lib/pages/roles_and_permission/users_page/add_user_dialog/view/add_user_dialog.dart b/lib/pages/roles_and_permission/users_page/add_user_dialog/view/add_user_dialog.dart index e4cf6107..1a487830 100644 --- a/lib/pages/roles_and_permission/users_page/add_user_dialog/view/add_user_dialog.dart +++ b/lib/pages/roles_and_permission/users_page/add_user_dialog/view/add_user_dialog.dart @@ -26,126 +26,118 @@ class _AddNewUserDialogState extends State { create: (BuildContext context) => UsersBloc() ..add(const LoadCommunityAndSpacesEvent()) ..add(const RoleEvent()), - child: BlocConsumer(listener: (context, state) { - // print('88888==${state}'); - // if (state is SpacesLoadedState) { - // print('object'); - // _blocRole.add(const CheckRoleStepStatus()); - // } - }, builder: (context, state) { - final _blocRole = BlocProvider.of(context); + child: BlocConsumer( + listener: (context, state) {}, + builder: (context, state) { + final _blocRole = BlocProvider.of(context); - return Dialog( - child: Container( - decoration: const BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(20))), - width: 900, - child: Column( - children: [ - // Title - const Padding( - padding: EdgeInsets.all(8.0), - child: SizedBox( - child: Text( - "Add New User", - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w700, - color: ColorsManager.secondaryColor), - ), - ), - ), - const Divider(), - Expanded( - child: Row( - children: [ - Expanded( - child: Container( - padding: const EdgeInsets.all(20), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - _buildStep1Indicator(1, "Basics", _blocRole), - _buildStep2Indicator(2, "Spaces", _blocRole), - _buildStep3Indicator( - 3, "Role & Permissions", _blocRole), - ], - ), - ), - ), - Container( - width: 1, - color: ColorsManager.grayBorder, - ), - Expanded( - flex: 2, - child: Padding( - padding: const EdgeInsets.all(20.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox(height: 10), - Expanded( - child: _getFormContent(), - ), - const SizedBox(height: 20), - ], - ), - ), - ), - ], - ), - ), - const Divider(), - Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - InkWell( - onTap: () { - Navigator.of(context).pop(); - }, - child: const Text("Cancel"), - ), - InkWell( - onTap: () { - _blocRole.add(const CheckEmailEvent()); - - setState(() { - if (currentStep < 3) { - currentStep++; - if (currentStep == 2) { - _blocRole.add( - const CheckStepStatus(isEditUser: false)); - } else if (currentStep == 3) { - _blocRole.add(const CheckSpacesStepStatus()); - } - } else { - _blocRole.add(SendInviteUsers(context: context)); - } - }); - }, + return Dialog( + child: Container( + decoration: const BoxDecoration( + color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(20))), + width: 900, + child: Column( + children: [ + // Title + const Padding( + padding: EdgeInsets.all(8.0), + child: SizedBox( child: Text( - currentStep < 3 ? "Next" : "Save", + "Add New User", style: TextStyle( - color: (_blocRole.isCompleteSpaces == false || - _blocRole.isCompleteBasics == false || - _blocRole.isCompleteRolePermissions == - false) && - currentStep == 3 - ? ColorsManager.grayColor - : ColorsManager.secondaryColor), + fontSize: 20, + fontWeight: FontWeight.w700, + color: ColorsManager.secondaryColor), ), ), - ], - ), + ), + const Divider(), + Expanded( + child: Row( + children: [ + Expanded( + child: Container( + padding: const EdgeInsets.all(20), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _buildStep1Indicator(1, "Basics", _blocRole), + _buildStep2Indicator(2, "Spaces", _blocRole), + _buildStep3Indicator(3, "Role & Permissions", _blocRole), + ], + ), + ), + ), + Container( + width: 1, + color: ColorsManager.grayBorder, + ), + Expanded( + flex: 2, + child: Padding( + padding: const EdgeInsets.all(20.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: 10), + Expanded( + child: _getFormContent(), + ), + const SizedBox(height: 20), + ], + ), + ), + ), + ], + ), + ), + const Divider(), + Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + InkWell( + onTap: () { + Navigator.of(context).pop(); + }, + child: const Text("Cancel"), + ), + InkWell( + onTap: () { + _blocRole.add(const CheckEmailEvent()); + + setState(() { + if (currentStep < 3) { + currentStep++; + if (currentStep == 2) { + _blocRole.add(const CheckStepStatus(isEditUser: false)); + } else if (currentStep == 3) { + _blocRole.add(const CheckSpacesStepStatus()); + } + } else { + _blocRole.add(SendInviteUsers(context: context)); + } + }); + }, + child: Text( + currentStep < 3 ? "Next" : "Save", + style: TextStyle( + color: (_blocRole.isCompleteSpaces == false || + _blocRole.isCompleteBasics == false || + _blocRole.isCompleteRolePermissions == false) && + currentStep == 3 + ? ColorsManager.grayColor + : ColorsManager.secondaryColor), + ), + ), + ], + ), + ), + ], ), - ], - ), - )); - })); + )); + })); } Widget _getFormContent() { @@ -204,12 +196,8 @@ class _AddNewUserDialogState extends State { label, style: TextStyle( fontSize: 16, - color: currentStep == step - ? ColorsManager.blackColor - : ColorsManager.greyColor, - fontWeight: currentStep == step - ? FontWeight.bold - : FontWeight.normal, + color: currentStep == step ? ColorsManager.blackColor : ColorsManager.greyColor, + fontWeight: currentStep == step ? FontWeight.bold : FontWeight.normal, ), ), ], @@ -272,12 +260,8 @@ class _AddNewUserDialogState extends State { label, style: TextStyle( fontSize: 16, - color: currentStep == step - ? ColorsManager.blackColor - : ColorsManager.greyColor, - fontWeight: currentStep == step - ? FontWeight.bold - : FontWeight.normal, + color: currentStep == step ? ColorsManager.blackColor : ColorsManager.greyColor, + fontWeight: currentStep == step ? FontWeight.bold : FontWeight.normal, ), ), ], @@ -334,12 +318,8 @@ class _AddNewUserDialogState extends State { label, style: TextStyle( fontSize: 16, - color: currentStep == step - ? ColorsManager.blackColor - : ColorsManager.greyColor, - fontWeight: currentStep == step - ? FontWeight.bold - : FontWeight.normal, + color: currentStep == step ? ColorsManager.blackColor : ColorsManager.greyColor, + fontWeight: currentStep == step ? FontWeight.bold : FontWeight.normal, ), ), ], diff --git a/lib/services/user_permission.dart b/lib/services/user_permission.dart index f3088794..e4f097f4 100644 --- a/lib/services/user_permission.dart +++ b/lib/services/user_permission.dart @@ -34,9 +34,8 @@ class UserPermissionApi { path: ApiEndpoints.roleTypes, showServerMessage: true, expectedResponseModel: (json) { - final List fetchedRoles = (json['data'] as List) - .map((item) => RoleTypeModel.fromJson(item)) - .toList(); + final List fetchedRoles = + (json['data'] as List).map((item) => RoleTypeModel.fromJson(item)).toList(); return fetchedRoles; }, ); @@ -48,9 +47,7 @@ class UserPermissionApi { path: ApiEndpoints.permission.replaceAll("roleUuid", roleUuid), showServerMessage: true, expectedResponseModel: (json) { - return (json as List) - .map((data) => PermissionOption.fromJson(data)) - .toList(); + return (json as List).map((data) => PermissionOption.fromJson(data)).toList(); }, ); return response ?? []; @@ -88,7 +85,6 @@ class UserPermissionApi { } }, ); - print('sendInviteUser=$body'); return response ?? []; } on DioException catch (e) { @@ -196,12 +192,9 @@ class UserPermissionApi { "disable": status, "projectUuid": "0e62577c-06fa-41b9-8a92-99a21fbaf51c" }; - print('changeUserStatusById==$bodya'); - print('changeUserStatusById==$userUuid'); final response = await _httpService.put( - path: ApiEndpoints.changeUserStatus - .replaceAll("{invitedUserUuid}", userUuid), + path: ApiEndpoints.changeUserStatus.replaceAll("{invitedUserUuid}", userUuid), body: bodya, expectedResponseModel: (json) { return json['success'];