From 9dd6c9e1e7f8b970d896fb5a13ed8a8c4dfda1fe Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Thu, 30 Jan 2025 21:15:00 +0400 Subject: [PATCH] updated logic of adding tag to subspace --- .../assign_tag/views/assign_tag_dialog.dart | 3 + .../views/assign_tag_models_dialog.dart | 58 +++---------------- 2 files changed, 10 insertions(+), 51 deletions(-) diff --git a/lib/pages/spaces_management/assign_tag/views/assign_tag_dialog.dart b/lib/pages/spaces_management/assign_tag/views/assign_tag_dialog.dart index cb1f7b46..5376cac8 100644 --- a/lib/pages/spaces_management/assign_tag/views/assign_tag_dialog.dart +++ b/lib/pages/spaces_management/assign_tag/views/assign_tag_dialog.dart @@ -350,6 +350,9 @@ class AssignTagDialog extends StatelessWidget { .tags ?.any((t) => t.internalId == tag.internalId) != true) { + if (modifiedSubspaces[newIndex].tags == null) { + modifiedSubspaces[newIndex].tags = []; + } tag.location = modifiedSubspaces[newIndex].subspaceName; modifiedSubspaces[newIndex].tags?.add(tag); } diff --git a/lib/pages/spaces_management/assign_tag_models/views/assign_tag_models_dialog.dart b/lib/pages/spaces_management/assign_tag_models/views/assign_tag_models_dialog.dart index 9696723a..436f6197 100644 --- a/lib/pages/spaces_management/assign_tag_models/views/assign_tag_models_dialog.dart +++ b/lib/pages/spaces_management/assign_tag_models/views/assign_tag_models_dialog.dart @@ -254,7 +254,7 @@ class AssignTagModelsDialog extends StatelessWidget { final updatedTags = List.from(state.tags); final result = - processTags(updatedTags, subspaces); + updateSubspaceTags(updatedTags, subspaces); final processedTags = result['updatedTags'] as List; @@ -305,8 +305,9 @@ class AssignTagModelsDialog extends StatelessWidget { ? () async { final updatedTags = List.from(state.tags); + final result = - processTags(updatedTags, subspaces); + updateSubspaceTags(updatedTags, subspaces); final processedTags = result['updatedTags'] as List; @@ -382,7 +383,7 @@ class AssignTagModelsDialog extends StatelessWidget { return null; } - Map processTags( + Map updateSubspaceTags( List updatedTags, List? subspaces) { final modifiedTags = List.from(updatedTags); final modifiedSubspaces = List.from(subspaces ?? []); @@ -401,29 +402,17 @@ class AssignTagModelsDialog extends StatelessWidget { final prevIndice = checkTagExistInSubspace(tag, modifiedSubspaces); - if ((tag.location == 'Main Space' || tag.location == null) && - (prevIndice == null || - modifiedSubspaces[prevIndice].subspaceName == 'Main Space')) { - continue; - } - - if ((tag.location == 'Main Space' || tag.location == null) && - prevIndice != null) { - modifiedSubspaces[prevIndice] - .tags - ?.removeWhere((t) => t.internalId == tag.internalId); - continue; - } - if ((tag.location != 'Main Space' && tag.location != null) && prevIndice == null) { final newIndex = modifiedSubspaces .indexWhere((subspace) => subspace.subspaceName == tag.location); + if (newIndex != -1) { if (modifiedSubspaces[newIndex] .tags ?.any((t) => t.internalId == tag.internalId) != true) { + modifiedSubspaces[newIndex].tags ??= []; tag.location = modifiedSubspaces[newIndex].subspaceName; modifiedSubspaces[newIndex].tags?.add(tag); } @@ -431,40 +420,6 @@ class AssignTagModelsDialog extends StatelessWidget { modifiedTags.removeWhere((t) => t.internalId == tag.internalId); continue; } - - if ((tag.location != 'Main Space' && tag.location != null) && - tag.location != modifiedSubspaces[prevIndice!].subspaceName) { - modifiedSubspaces[prevIndice] - .tags - ?.removeWhere((t) => t.internalId == tag.internalId); - final newIndex = modifiedSubspaces - .indexWhere((subspace) => subspace.subspaceName == tag.location); - if (newIndex != -1) { - if (modifiedSubspaces[newIndex] - .tags - ?.any((t) => t.internalId == tag.internalId) != - true) { - tag.location = modifiedSubspaces[newIndex].subspaceName; - modifiedSubspaces[newIndex].tags?.add(tag); - } - } - - modifiedTags.removeWhere((t) => t.internalId == tag.internalId); - continue; - } - - if ((tag.location != 'Main Space' && tag.location != null) && - tag.location == modifiedSubspaces[prevIndice!].subspaceName) { - modifiedTags.removeWhere((t) => t.internalId == tag.internalId); - continue; - } - - if ((tag.location == 'Main Space' || tag.location == null) && - prevIndice != null) { - modifiedSubspaces[prevIndice] - .tags - ?.removeWhere((t) => t.internalId == tag.internalId); - } } return { @@ -472,4 +427,5 @@ class AssignTagModelsDialog extends StatelessWidget { 'subspaces': modifiedSubspaces, }; } + }