validation fix

This commit is contained in:
hannathkadher
2025-01-23 17:48:11 +04:00
parent dac045146e
commit d4ed4efcd8
4 changed files with 18 additions and 24 deletions

View File

@ -70,8 +70,7 @@ class CreateSpaceModelBloc
_space = event.spaceTemplate;
final String? errorMessage = _checkDuplicateModelName(
event.allModels ?? [], event.spaceTemplate.modelName);
emit(CreateSpaceModelLoaded(_space!,errorMessage: errorMessage ?? ''));
emit(CreateSpaceModelLoaded(_space!, errorMessage: errorMessage));
});
on<AddSubspacesToSpaceTemplate>((event, emit) {
@ -136,7 +135,7 @@ class CreateSpaceModelBloc
final updatedSpace =
currentState.space.copyWith(subspaceModels: updatedSubspaces);
emit(CreateSpaceModelLoaded(updatedSpace));
emit(CreateSpaceModelLoaded(updatedSpace,errorMessage: currentState.errorMessage));
} else {
emit(CreateSpaceModelError("Space template not initialized"));
}
@ -243,7 +242,7 @@ class CreateSpaceModelBloc
for (var tag in newSubspace.tags!) {
tagUpdates.add(TagModelUpdate(
action: Action.add,
uuid: tag.uuid,
uuid: tag.uuid == '' ? null : tag.uuid,
tag: tag.tag,
productUuid: tag.product?.uuid));
}
@ -330,7 +329,7 @@ class CreateSpaceModelBloc
tagUpdates.add(TagModelUpdate(
action: Action.add,
tag: newTag.tag,
uuid: newTag.uuid,
uuid: newTag.uuid == '' ? null : newTag.uuid,
productUuid: newTag.product?.uuid));
processedTags.add(newTag.tag);
}

View File

@ -1,5 +1,5 @@
class TagBodyModel {
late String uuid;
late String? uuid;
late String tag;
late final String? productUuid;

View File

@ -58,7 +58,7 @@ class TagModel extends BaseTag {
extension TagModelExtensions on TagModel {
TagBodyModel toTagBodyModel() {
return TagBodyModel()
..uuid = uuid ?? ''
..uuid = uuid
..tag = tag ?? ''
..productUuid = product?.uuid;
}

View File

@ -52,12 +52,14 @@ class CreateSpaceModelDialog extends StatelessWidget {
create: (_) {
final bloc = CreateSpaceModelBloc(_spaceModelApi);
if (spaceModel != null) {
bloc.add(UpdateSpaceTemplate(spaceModel!,otherSpaceModels));
bloc.add(UpdateSpaceTemplate(spaceModel!, otherSpaceModels));
} else {
bloc.add(UpdateSpaceTemplate(SpaceTemplateModel(
modelName: '',
subspaceModels: const [],
),otherSpaceModels));
bloc.add(UpdateSpaceTemplate(
SpaceTemplateModel(
modelName: '',
subspaceModels: const [],
),
otherSpaceModels));
}
spaceNameController.addListener(() {
@ -127,11 +129,6 @@ class CreateSpaceModelDialog extends StatelessWidget {
context
.read<CreateSpaceModelBloc>()
.add(AddSubspacesToSpaceTemplate(updatedSubspaces));
context.read<CreateSpaceModelBloc>().add(
UpdateSpaceTemplateName(
name: spaceNameController.text,
allModels: otherSpaceModels ?? []));
},
),
const SizedBox(height: 10),
@ -163,10 +160,8 @@ class CreateSpaceModelDialog extends StatelessWidget {
const SizedBox(width: 10),
Expanded(
child: DefaultButton(
onPressed: ( state.errorMessage == null) &&
isNameValid
onPressed: (state.errorMessage == null)
? () {
final updatedSpaceTemplate =
updatedSpaceModel.copyWith(
modelName:
@ -243,10 +238,10 @@ class CreateSpaceModelDialog extends StatelessWidget {
: null,
backgroundColor: ColorsManager.secondaryColor,
borderRadius: 10,
foregroundColor:
state.errorMessage == null && isNameValid
? ColorsManager.whiteColors
: ColorsManager.whiteColorsWithOpacity,
foregroundColor: (state.errorMessage != null &&
state.errorMessage != '')
? ColorsManager.whiteColorsWithOpacity
: ColorsManager.whiteColors,
child: const Text('OK'),
),
),