mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
added empty name validation
This commit is contained in:
@ -59,18 +59,6 @@ class CreateSpaceModelBloc
|
|||||||
emit(CreateSpaceModelLoaded(_space!));
|
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) {
|
on<AddSubspacesToSpaceTemplate>((event, emit) {
|
||||||
final currentState = state;
|
final currentState = state;
|
||||||
|
|
||||||
@ -86,5 +74,31 @@ class CreateSpaceModelBloc
|
|||||||
emit(CreateSpaceModelError("Space template not initialized"));
|
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"));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,3 +42,9 @@ class AddSubspacesToSpaceTemplate extends CreateSpaceModelEvent {
|
|||||||
|
|
||||||
AddSubspacesToSpaceTemplate(this.subspaces);
|
AddSubspacesToSpaceTemplate(this.subspaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ValidateSpaceTemplateName extends CreateSpaceModelEvent {
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
ValidateSpaceTemplateName({required this.name});
|
||||||
|
}
|
@ -5,7 +5,7 @@ abstract class CreateSpaceModelState extends Equatable {
|
|||||||
const CreateSpaceModelState();
|
const CreateSpaceModelState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [];
|
List<Object?> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
class CreateSpaceModelInitial extends CreateSpaceModelState {}
|
class CreateSpaceModelInitial extends CreateSpaceModelState {}
|
||||||
@ -14,8 +14,12 @@ class CreateSpaceModelLoading extends CreateSpaceModelState {}
|
|||||||
|
|
||||||
class CreateSpaceModelLoaded extends CreateSpaceModelState {
|
class CreateSpaceModelLoaded extends CreateSpaceModelState {
|
||||||
final SpaceTemplateModel space;
|
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 {
|
class CreateSpaceModelError extends CreateSpaceModelState {
|
||||||
|
@ -34,9 +34,10 @@ class SpaceTemplateModel extends Equatable {
|
|||||||
?.map((e) => SubspaceTemplateModel.fromJson(e))
|
?.map((e) => SubspaceTemplateModel.fromJson(e))
|
||||||
.toList() ??
|
.toList() ??
|
||||||
[],
|
[],
|
||||||
tags: (json['tags'] as List)
|
tags: (json['tags'] as List<dynamic>?)
|
||||||
.map((item) => TagModel.fromJson(item))
|
?.map((item) => TagModel.fromJson(item))
|
||||||
.toList(),
|
.toList() ??
|
||||||
|
[],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,9 +18,10 @@ class SubspaceTemplateModel {
|
|||||||
uuid: json['uuid'] ?? '',
|
uuid: json['uuid'] ?? '',
|
||||||
subspaceName: json['subspaceName'] ?? '',
|
subspaceName: json['subspaceName'] ?? '',
|
||||||
disabled: json['disabled'] ?? false,
|
disabled: json['disabled'] ?? false,
|
||||||
tags: (json['tags'] as List)
|
tags: (json['tags'] as List<dynamic>?)
|
||||||
.map((item) => TagModel.fromJson(item))
|
?.map((item) => TagModel.fromJson(item))
|
||||||
.toList(),
|
.toList() ??
|
||||||
|
[],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
} else if (state is CreateSpaceModelLoaded) {
|
} else if (state is CreateSpaceModelLoaded) {
|
||||||
final updatedSpaceModel = state.space;
|
final updatedSpaceModel = state.space;
|
||||||
final subspaces = updatedSpaceModel.subspaceModels ?? [];
|
final subspaces = updatedSpaceModel.subspaceModels ?? [];
|
||||||
|
final isNameValid = spaceNameController.text.trim().isNotEmpty;
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@ -87,6 +88,7 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
filled: true,
|
filled: true,
|
||||||
fillColor: ColorsManager.textFieldGreyColor,
|
fillColor: ColorsManager.textFieldGreyColor,
|
||||||
hintText: 'Please enter the name',
|
hintText: 'Please enter the name',
|
||||||
|
errorText: state.errorMessage,
|
||||||
hintStyle: const TextStyle(
|
hintStyle: const TextStyle(
|
||||||
color: ColorsManager.lightGrayColor),
|
color: ColorsManager.lightGrayColor),
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
@ -130,19 +132,26 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: DefaultButton(
|
child: DefaultButton(
|
||||||
onPressed: () {
|
onPressed: state.errorMessage == null ||
|
||||||
final updatedSpaceTemplate =
|
isNameValid
|
||||||
updatedSpaceModel.copyWith(
|
? () {
|
||||||
modelName: spaceNameController.text.trim(),
|
final updatedSpaceTemplate =
|
||||||
);
|
updatedSpaceModel.copyWith(
|
||||||
context.read<CreateSpaceModelBloc>().add(
|
modelName:
|
||||||
CreateSpaceTemplate(
|
spaceNameController.text.trim(),
|
||||||
spaceTemplate: updatedSpaceTemplate),
|
);
|
||||||
);
|
context.read<CreateSpaceModelBloc>().add(
|
||||||
},
|
CreateSpaceTemplate(
|
||||||
|
spaceTemplate:
|
||||||
|
updatedSpaceTemplate),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
backgroundColor: ColorsManager.secondaryColor,
|
backgroundColor: ColorsManager.secondaryColor,
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
foregroundColor: ColorsManager.whiteColors,
|
foregroundColor: isNameValid
|
||||||
|
? ColorsManager.whiteColors
|
||||||
|
: ColorsManager.whiteColorsWithOpacity,
|
||||||
child: const Text('OK'),
|
child: const Text('OK'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -158,7 +167,6 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default case (e.g., CreateSpaceModelInitial)
|
|
||||||
return const Center(child: Text('Initializing...'));
|
return const Center(child: Text('Initializing...'));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -5,8 +5,11 @@ abstract class ColorsManager {
|
|||||||
static const Color switchOffColor = Color(0x7F8D99AE);
|
static const Color switchOffColor = Color(0x7F8D99AE);
|
||||||
static const Color primaryColor = Color(0xFF0030CB); //023DFE
|
static const Color primaryColor = Color(0xFF0030CB); //023DFE
|
||||||
static const Color secondaryTextColor = Color(0xFF848484);
|
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 const Color whiteColors = Colors.white;
|
||||||
|
static Color whiteColorsWithOpacity = Colors.white.withOpacity(0.6);
|
||||||
|
|
||||||
static const Color secondaryColor = Color(0xFF023DFE);
|
static const Color secondaryColor = Color(0xFF023DFE);
|
||||||
static const Color onSecondaryColor = Color(0xFF023DFE);
|
static const Color onSecondaryColor = Color(0xFF023DFE);
|
||||||
static Color shadowBlackColor = Colors.black.withOpacity(0.2);
|
static Color shadowBlackColor = Colors.black.withOpacity(0.2);
|
||||||
|
Reference in New Issue
Block a user