added empty name validation

This commit is contained in:
hannathkadher
2025-01-08 21:04:03 +04:00
parent 9b3e4a59af
commit 17e025b69f
7 changed files with 70 additions and 33 deletions

View File

@ -59,18 +59,6 @@ class CreateSpaceModelBloc
emit(CreateSpaceModelLoaded(_space!));
});
on<UpdateSpaceTemplateName>((event, emit) {
final currentState = state;
if (currentState is CreateSpaceModelLoaded) {
final updatedSpaceModel =
currentState.space.copyWith(modelName: event.name);
emit(CreateSpaceModelLoaded(updatedSpaceModel));
} else {
emit(CreateSpaceModelError("Space template not initialized"));
}
});
on<AddSubspacesToSpaceTemplate>((event, emit) {
final currentState = state;
@ -86,5 +74,31 @@ class CreateSpaceModelBloc
emit(CreateSpaceModelError("Space template not initialized"));
}
});
on<UpdateSpaceTemplateName>((event, emit) {
final currentState = state;
print('Current State: $currentState');
if (currentState is CreateSpaceModelLoaded) {
if (event.name.trim().isEmpty) {
print("set error message");
emit(CreateSpaceModelLoaded(
currentState.space,
errorMessage: "Model name cannot be empty",
));
print('State emitted: CreateSpaceModelLoaded with updated model:');
} else {
final updatedSpaceModel =
currentState.space.copyWith(modelName: event.name);
print(
'State emitted: CreateSpaceModelLoaded with updated model: $updatedSpaceModel');
emit(CreateSpaceModelLoaded(updatedSpaceModel));
}
} else {
emit(CreateSpaceModelError("Space template not initialized"));
}
});
}
}

View File

@ -42,3 +42,9 @@ class AddSubspacesToSpaceTemplate extends CreateSpaceModelEvent {
AddSubspacesToSpaceTemplate(this.subspaces);
}
class ValidateSpaceTemplateName extends CreateSpaceModelEvent {
final String name;
ValidateSpaceTemplateName({required this.name});
}

View File

@ -5,7 +5,7 @@ abstract class CreateSpaceModelState extends Equatable {
const CreateSpaceModelState();
@override
List<Object> get props => [];
List<Object?> get props => [];
}
class CreateSpaceModelInitial extends CreateSpaceModelState {}
@ -14,8 +14,12 @@ class CreateSpaceModelLoading extends CreateSpaceModelState {}
class CreateSpaceModelLoaded extends CreateSpaceModelState {
final SpaceTemplateModel space;
final String? errorMessage;
CreateSpaceModelLoaded(this.space);
CreateSpaceModelLoaded(this.space, {this.errorMessage});
@override
List<Object?> get props => [space, errorMessage];
}
class CreateSpaceModelError extends CreateSpaceModelState {

View File

@ -34,9 +34,10 @@ class SpaceTemplateModel extends Equatable {
?.map((e) => SubspaceTemplateModel.fromJson(e))
.toList() ??
[],
tags: (json['tags'] as List)
.map((item) => TagModel.fromJson(item))
.toList(),
tags: (json['tags'] as List<dynamic>?)
?.map((item) => TagModel.fromJson(item))
.toList() ??
[],
);
}

View File

@ -18,9 +18,10 @@ class SubspaceTemplateModel {
uuid: json['uuid'] ?? '',
subspaceName: json['subspaceName'] ?? '',
disabled: json['disabled'] ?? false,
tags: (json['tags'] as List)
.map((item) => TagModel.fromJson(item))
.toList(),
tags: (json['tags'] as List<dynamic>?)
?.map((item) => TagModel.fromJson(item))
.toList() ??
[],
);
}

View File

@ -61,6 +61,7 @@ class CreateSpaceModelDialog extends StatelessWidget {
} else if (state is CreateSpaceModelLoaded) {
final updatedSpaceModel = state.space;
final subspaces = updatedSpaceModel.subspaceModels ?? [];
final isNameValid = spaceNameController.text.trim().isNotEmpty;
return Column(
mainAxisSize: MainAxisSize.min,
@ -87,6 +88,7 @@ class CreateSpaceModelDialog extends StatelessWidget {
filled: true,
fillColor: ColorsManager.textFieldGreyColor,
hintText: 'Please enter the name',
errorText: state.errorMessage,
hintStyle: const TextStyle(
color: ColorsManager.lightGrayColor),
border: OutlineInputBorder(
@ -130,19 +132,26 @@ class CreateSpaceModelDialog extends StatelessWidget {
const SizedBox(width: 10),
Expanded(
child: DefaultButton(
onPressed: () {
onPressed: state.errorMessage == null ||
isNameValid
? () {
final updatedSpaceTemplate =
updatedSpaceModel.copyWith(
modelName: spaceNameController.text.trim(),
modelName:
spaceNameController.text.trim(),
);
context.read<CreateSpaceModelBloc>().add(
CreateSpaceTemplate(
spaceTemplate: updatedSpaceTemplate),
spaceTemplate:
updatedSpaceTemplate),
);
},
}
: null,
backgroundColor: ColorsManager.secondaryColor,
borderRadius: 10,
foregroundColor: ColorsManager.whiteColors,
foregroundColor: isNameValid
? ColorsManager.whiteColors
: ColorsManager.whiteColorsWithOpacity,
child: const Text('OK'),
),
),
@ -158,7 +167,6 @@ class CreateSpaceModelDialog extends StatelessWidget {
);
}
// Default case (e.g., CreateSpaceModelInitial)
return const Center(child: Text('Initializing...'));
},
),

View File

@ -5,8 +5,11 @@ abstract class ColorsManager {
static const Color switchOffColor = Color(0x7F8D99AE);
static const Color primaryColor = Color(0xFF0030CB); //023DFE
static const Color secondaryTextColor = Color(0xFF848484);
static Color primaryColorWithOpacity = const Color(0xFF023DFE).withOpacity(0.6);
static Color primaryColorWithOpacity =
const Color(0xFF023DFE).withOpacity(0.6);
static const Color whiteColors = Colors.white;
static Color whiteColorsWithOpacity = Colors.white.withOpacity(0.6);
static const Color secondaryColor = Color(0xFF023DFE);
static const Color onSecondaryColor = Color(0xFF023DFE);
static Color shadowBlackColor = Colors.black.withOpacity(0.2);