fixed the edit flow of space

This commit is contained in:
hannathkadher
2025-01-29 09:56:10 +04:00
parent 9331193e90
commit 8870467fe4
5 changed files with 43 additions and 21 deletions

View File

@ -195,6 +195,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
screenSize,
position:
spaces[index].position + newPosition,
parentIndex: index,
direction: direction,
);
@ -305,6 +306,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
// Set the first space in the center or use passed position
Offset centerPosition =
position ?? _getCenterPosition(screenSize);
print(tags);
SpaceModel newSpace = SpaceModel(
name: name,
icon: icon,
@ -350,6 +352,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
name: widget.selectedSpace!.name,
icon: widget.selectedSpace!.icon,
editSpace: widget.selectedSpace,
tags: widget.selectedSpace?.tags,
subspaces: widget.selectedSpace?.subspaces,
isEdit: true,
onCreateSpace: (String name,
String icon,

View File

@ -12,6 +12,7 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
import 'package:syncrow_web/pages/spaces_management/assign_tag/bloc/assign_tag_bloc.dart';
import 'package:syncrow_web/pages/spaces_management/assign_tag/bloc/assign_tag_event.dart';
import 'package:syncrow_web/pages/spaces_management/assign_tag/bloc/assign_tag_state.dart';
import 'package:syncrow_web/pages/spaces_management/helper/tag_helper.dart';
import 'package:syncrow_web/utils/color_manager.dart';
class AssignTagDialog extends StatelessWidget {
@ -40,8 +41,11 @@ class AssignTagDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
final List<String> locations =
(subspaces ?? []).map((subspace) => subspace.subspaceName).toList();
final List<String> locations = (subspaces ?? [])
.map((subspace) => subspace.subspaceName)
.toList()
..add('Main Space');
return BlocProvider(
create: (_) => AssignTagBloc()
..add(InitializeTags(
@ -235,16 +239,18 @@ class AssignTagDialog extends StatelessWidget {
Navigator.of(context).pop();
await showDialog<bool>(
barrierDismissible: false,
await showDialog(
context: context,
builder: (dialogContext) => AddDeviceTypeWidget(
builder: (context) => AddDeviceTypeWidget(
products: products,
subspaces: processedSubspaces,
initialSelectedProducts: addedProducts,
allTags: allTags,
initialSelectedProducts: TagHelper
.createInitialSelectedProductsForTags(
processedTags, processedSubspaces),
spaceName: spaceName,
spaceTags: processedTags,
isCreate: false,
onSave: onSave,
),
);
},
@ -261,7 +267,6 @@ class AssignTagDialog extends StatelessWidget {
foregroundColor: ColorsManager.whiteColors,
onPressed: state.isSaveEnabled
? () async {
Navigator.of(context).pop();
final updatedTags = List<Tag>.from(state.tags);
final result =
processTags(updatedTags, subspaces);
@ -270,8 +275,8 @@ class AssignTagDialog extends StatelessWidget {
result['updatedTags'] as List<Tag>;
final processedSubspaces =
result['subspaces'] as List<SubspaceModel>;
onSave!(processedTags, processedSubspaces);
onSave?.call(processedTags, processedSubspaces);
Navigator.of(context).pop();
}
: null,
child: const Text('Save'),
@ -307,7 +312,15 @@ class AssignTagDialog extends StatelessWidget {
final modifiedTags = List<Tag>.from(updatedTags);
final modifiedSubspaces = List<SubspaceModel>.from(subspaces ?? []);
for (var tag in modifiedTags.toList()) {
if (subspaces != null) {
for (var subspace in subspaces) {
subspace.tags?.removeWhere(
(tag) => !modifiedTags
.any((updatedTag) => updatedTag.internalId == tag.internalId),
);
}
}
for (var tag in modifiedTags.toList()) {
if (modifiedSubspaces.isEmpty) continue;
final prevIndice = checkTagExistInSubspace(tag, modifiedSubspaces);

View File

@ -268,7 +268,7 @@ class AssignTagModelsDialog extends StatelessWidget {
builder: (dialogContext) =>
AddDeviceTypeModelWidget(
products: products,
subspaces: subspaces,
subspaces: processedSubspaces,
isCreate: false,
initialSelectedProducts: TagHelper
.createInitialSelectedProducts(

View File

@ -193,17 +193,21 @@ class CreateSubSpaceDialog extends StatelessWidget {
const SizedBox(width: 10),
Expanded(
child: DefaultButton(
onPressed: () async {
final subSpaces = context
.read<SubSpaceBloc>()
.state
.subSpaces;
onSave!(subSpaces);
Navigator.of(context).pop();
},
onPressed: (state.errorMessage.isNotEmpty)
? null
: () async {
final subSpaces = context
.read<SubSpaceBloc>()
.state
.subSpaces;
onSave!(subSpaces);
Navigator.of(context).pop();
},
backgroundColor: ColorsManager.secondaryColor,
borderRadius: 10,
foregroundColor: ColorsManager.whiteColors,
foregroundColor: state.errorMessage.isNotEmpty
? ColorsManager.whiteColorsWithOpacity
: ColorsManager.whiteColors,
child: const Text('OK'),
),
),

View File

@ -105,6 +105,7 @@ class _SubspaceModelCreateState extends State<SubspaceModelCreate> {
isEdit: true,
dialogTitle: dialogTitle,
existingSubSpaces: _subspaces,
onUpdate: (subspaceModels) {
setState(() {
_subspaces = subspaceModels;