fixed space model creation

This commit is contained in:
hannathkadher
2025-01-21 20:26:30 +04:00
parent 788ea27de1
commit e47f3d6d59
7 changed files with 144 additions and 126 deletions

View File

@ -8,6 +8,8 @@ import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_spac
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_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';
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_event.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/subspace_model_create_widget.dart';
import 'package:syncrow_web/services/space_model_mang_api.dart';
@ -17,15 +19,17 @@ class CreateSpaceModelDialog extends StatelessWidget {
final List<ProductModel>? products;
final List<String>? allTags;
final SpaceTemplateModel? spaceModel;
final void Function(SpaceTemplateModel newModel)? onLoad;
final BuildContext? pageContext;
final List<String>? otherSpaceModels;
const CreateSpaceModelDialog({
Key? key,
this.products,
this.allTags,
this.spaceModel,
this.onLoad,
}) : super(key: key);
const CreateSpaceModelDialog(
{Key? key,
this.products,
this.allTags,
this.spaceModel,
this.pageContext,
this.otherSpaceModels})
: super(key: key);
@override
Widget build(BuildContext context) {
@ -44,17 +48,17 @@ class CreateSpaceModelDialog extends StatelessWidget {
child: BlocProvider(
create: (_) {
final bloc = CreateSpaceModelBloc(_spaceModelApi);
if (spaceModel != null) {
bloc.add(UpdateSpaceTemplate(spaceModel!));
} else {
bloc.add(UpdateSpaceTemplate(SpaceTemplateModel(
modelName: '',
subspaceModels: const [],
)));
}
if (spaceModel != null) {
bloc.add(UpdateSpaceTemplate(spaceModel!));
} else {
bloc.add(UpdateSpaceTemplate(SpaceTemplateModel(
modelName: '',
subspaceModels: const [],
)));
}
spaceNameController.addListener(() {
bloc.add(UpdateSpaceTemplateName(name: spaceNameController.text));
bloc.add(UpdateSpaceTemplateName(name: spaceNameController.text,allModels: otherSpaceModels ??[]));
});
return bloc;
@ -86,9 +90,10 @@ class CreateSpaceModelDialog extends StatelessWidget {
child: TextField(
controller: spaceNameController,
onChanged: (value) {
context
.read<CreateSpaceModelBloc>()
.add(UpdateSpaceTemplateName(name: value));
context.read<CreateSpaceModelBloc>().add(
UpdateSpaceTemplateName(
name: value,
allModels: otherSpaceModels ?? []));
},
style: const TextStyle(color: ColorsManager.blackColor),
decoration: InputDecoration(
@ -128,21 +133,8 @@ class CreateSpaceModelDialog extends StatelessWidget {
subspaces: subspaces,
allTags: allTags,
spaceNameController: spaceNameController,
onLoad: (tags, subspaces) {
if (context.read<CreateSpaceModelBloc>().state
is CreateSpaceModelLoaded) {
if (subspaces != null) {
context
.read<CreateSpaceModelBloc>()
.add(AddSubspacesToSpaceTemplate(subspaces));
}
if (tags != null) {
context
.read<CreateSpaceModelBloc>()
.add(AddTagsToSpaceTemplate(tags));
}
}
},
pageContext: pageContext,
otherSpaceModels: otherSpaceModels,
),
const SizedBox(height: 20),
SizedBox(
@ -161,26 +153,35 @@ class CreateSpaceModelDialog extends StatelessWidget {
onPressed: state.errorMessage == null ||
isNameValid
? () {
final updatedSpaceTemplate =
updatedSpaceModel.copyWith(
modelName:
spaceNameController.text.trim(),
);
if(updatedSpaceTemplate.uuid != null){
if (updatedSpaceModel.uuid == null) {
final updatedSpaceTemplate =
updatedSpaceModel.copyWith(
modelName:
spaceNameController.text.trim(),
);
if (updatedSpaceTemplate.uuid !=
null) {}
context
.read<CreateSpaceModelBloc>()
.add(
CreateSpaceTemplate(
spaceTemplate:
updatedSpaceTemplate,
onCreate: (newModel) {
if (pageContext != null) {
pageContext!
.read<SpaceModelBloc>()
.add(CreateSpaceModel(
newSpaceModel:
newModel));
}
Navigator.of(context)
.pop(); // Close the dialog
},
),
);
}
context.read<CreateSpaceModelBloc>().add(
CreateSpaceTemplate(
spaceTemplate:
updatedSpaceTemplate,
onCreate: (newModel) {
onLoad!(newModel);
Navigator.of(context)
.pop(); // Close the dialog
},
),
);
}
: null,
backgroundColor: ColorsManager.secondaryColor,