fixed the edit flow for space model

This commit is contained in:
hannathkadher
2025-01-22 12:49:47 +04:00
parent 7ffdc67016
commit f35b699d4c
24 changed files with 517 additions and 127 deletions

View File

@ -6,6 +6,7 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_mod
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_bloc.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_event.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_state.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_state.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_bloc.dart';
@ -58,7 +59,9 @@ class CreateSpaceModelDialog extends StatelessWidget {
}
spaceNameController.addListener(() {
bloc.add(UpdateSpaceTemplateName(name: spaceNameController.text,allModels: otherSpaceModels ??[]));
bloc.add(UpdateSpaceTemplateName(
name: spaceNameController.text,
allModels: otherSpaceModels ?? []));
});
return bloc;
@ -153,15 +156,12 @@ class CreateSpaceModelDialog extends StatelessWidget {
onPressed: state.errorMessage == null ||
isNameValid
? () {
final updatedSpaceTemplate =
updatedSpaceModel.copyWith(
modelName:
spaceNameController.text.trim(),
);
if (updatedSpaceModel.uuid == null) {
final updatedSpaceTemplate =
updatedSpaceModel.copyWith(
modelName:
spaceNameController.text.trim(),
);
if (updatedSpaceTemplate.uuid !=
null) {}
context
.read<CreateSpaceModelBloc>()
.add(
@ -181,6 +181,52 @@ class CreateSpaceModelDialog extends StatelessWidget {
},
),
);
} else {
if (pageContext != null) {
final currentState = pageContext!
.read<SpaceModelBloc>()
.state;
if (currentState
is SpaceModelLoaded) {
final spaceModels =
List<SpaceTemplateModel>.from(
currentState.spaceModels);
final SpaceTemplateModel?
currentSpaceModel = spaceModels
.cast<SpaceTemplateModel?>()
.firstWhere(
(sm) =>
sm?.uuid ==
updatedSpaceModel
.uuid,
orElse: () => null,
);
if (currentSpaceModel != null) {
context
.read<CreateSpaceModelBloc>()
.add(ModifySpaceTemplate(
spaceTemplate:
currentSpaceModel,
updatedSpaceTemplate:
updatedSpaceTemplate,
onUpdate: (newModel) {
if (pageContext !=
null) {
pageContext!
.read<
SpaceModelBloc>()
.add(UpdateSpaceModel(
spaceModelUuid:
newModel.uuid ??
''));
}
Navigator.of(context)
.pop();
}));
}
}
}
}
}
: null,

View File

@ -1,9 +1,6 @@
import 'package:flutter/material.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:flutter/material.dart';
import 'package:syncrow_web/utils/color_manager.dart';
class SubspaceChipWidget extends StatelessWidget {
final String subspace;

View File

@ -46,23 +46,23 @@ class SubspaceModelCreate extends StatelessWidget {
spacing: 8.0,
runSpacing: 8.0,
children: [
...subspaces.map(
(subspace) => Chip(
label: Text(
subspace.subspaceName,
style: const TextStyle(
color: ColorsManager.spaceColor), // Text color
),
backgroundColor:
ColorsManager.whiteColors, // Chip background color
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(16), // Rounded chip
side: const BorderSide(
color: ColorsManager.spaceColor), // Border color
),
),
),
...subspaces.map((subspace) => Container(
padding: const EdgeInsets.symmetric(
horizontal: 8.0, vertical: 4.0),
decoration: BoxDecoration(
color: ColorsManager.whiteColors,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: ColorsManager.transparentColor),
),
child: Text(
subspace.subspaceName,
style: Theme.of(context)
.textTheme
.bodySmall
?.copyWith(color: ColorsManager.spaceColor),
),
)),
GestureDetector(
onTap: () async {
await _openDialog(context, 'Edit Sub-space');

View File

@ -98,6 +98,7 @@ class TagChipDisplay extends StatelessWidget {
subspaces: subspaces,
pageContext: pageContext,
allTags: allTags,
spaceModel: spaceModel,
initialTags: TagHelper.generateInitialTags(
subspaces: subspaces,
spaceTagModels: spaceModel?.tags ?? []),
@ -139,6 +140,7 @@ class TagChipDisplay extends StatelessWidget {
spaceName: spaceNameController.text,
pageContext: pageContext,
isCreate: true,
spaceModel: spaceModel,
),
);
},