added white background color to container

This commit is contained in:
hannathkadher
2025-01-05 12:07:48 +04:00
parent 67ad986fcc
commit 1d35377137
4 changed files with 182 additions and 124 deletions

View File

@ -4,15 +4,36 @@ import 'package:syncrow_web/pages/spaces_management/space_model/bloc/subspace_mo
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
import 'package:syncrow_web/utils/constants/action_enum.dart';
// BLoC
class SubSpaceModelBloc extends Bloc<SubSpaceModelEvent, SubSpaceModelState> {
SubSpaceModelBloc() : super(SubSpaceModelState([], [])) {
SubSpaceModelBloc() : super(SubSpaceModelState([], [], '')) {
// Handle AddSubSpaceModel Event
on<AddSubSpaceModel>((event, emit) {
final updatedSubSpaces = List<SubspaceTemplateModel>.from(state.subSpaces)
// Check for duplicate names (case-insensitive)
final existingNames =
state.subSpaces.map((e) => e.subspaceName.toLowerCase()).toSet();
if (existingNames.contains(event.subSpace.subspaceName.toLowerCase())) {
// Emit state with an error message if duplicate name exists
emit(SubSpaceModelState(
state.subSpaces,
state.updatedSubSpaceModels,
'Subspace name already exists.',
));
} else {
// Add subspace if no duplicate exists
final updatedSubSpaces =
List<SubspaceTemplateModel>.from(state.subSpaces)
..add(event.subSpace);
emit(SubSpaceModelState(updatedSubSpaces, state.updatedSubSpaceModels));
emit(SubSpaceModelState(
updatedSubSpaces,
state.updatedSubSpaceModels,
'', // Clear error message
));
}
});
// Handle RemoveSubSpaceModel Event
on<RemoveSubSpaceModel>((event, emit) {
final updatedSubSpaces = List<SubspaceTemplateModel>.from(state.subSpaces)
..remove(event.subSpace);
@ -28,9 +49,14 @@ class SubSpaceModelBloc extends Bloc<SubSpaceModelEvent, SubSpaceModelState> {
));
}
emit(SubSpaceModelState(updatedSubSpaces, updatedSubspaceModels));
emit(SubSpaceModelState(
updatedSubSpaces,
updatedSubspaceModels,
'', // Clear error message
));
});
// Handle UpdateSubSpaceModel Event
on<UpdateSubSpaceModel>((event, emit) {
final updatedSubSpaces = state.subSpaces.map((subSpace) {
if (subSpace.uuid == event.updatedSubSpace.uuid) {
@ -48,7 +74,11 @@ class SubSpaceModelBloc extends Bloc<SubSpaceModelEvent, SubSpaceModelState> {
uuid: event.updatedSubSpace.uuid!,
));
emit(SubSpaceModelState(updatedSubSpaces, updatedSubspaceModels));
emit(SubSpaceModelState(
updatedSubSpaces,
updatedSubspaceModels,
'', // Clear error message
));
});
}
}

View File

@ -3,9 +3,23 @@ import 'package:syncrow_web/pages/spaces_management/space_model/models/space_tem
class SubSpaceModelState {
final List<SubspaceTemplateModel> subSpaces;
final List<UpdateSubspaceTemplateModel> updatedSubSpaceModels;
final String errorMessage;
SubSpaceModelState(
this.subSpaces,
this.updatedSubSpaceModels,
this.errorMessage,
);
SubSpaceModelState copyWith({
List<SubspaceTemplateModel>? subSpaces,
List<UpdateSubspaceTemplateModel>? updatedSubSpaceModels,
String? errorMessage,
}) {
return SubSpaceModelState(
subSpaces ?? this.subSpaces,
updatedSubSpaceModels ?? this.updatedSubSpaceModels,
errorMessage ?? this.errorMessage,
);
}
}

View File

@ -102,7 +102,7 @@ class CreateSpaceModelDialog extends StatelessWidget {
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
),
child: ButtonContentWidget(
child: const ButtonContentWidget(
icon: Icons.add,
label: 'Add Devices',
),

View File

@ -41,7 +41,9 @@ class CreateSubSpaceModelDialog extends StatelessWidget {
},
child: BlocBuilder<SubSpaceModelBloc, SubSpaceModelState>(
builder: (context, state) {
return SizedBox(
return Container(
color: ColorsManager.whiteColors,
child: SizedBox(
width: screenWidth * 0.35,
child: Padding(
padding: const EdgeInsets.all(16.0),
@ -120,7 +122,8 @@ class CreateSubSpaceModelDialog extends StatelessWidget {
onSubmitted: (value) {
if (value.trim().isNotEmpty) {
context.read<SubSpaceModelBloc>().add(
AddSubSpaceModel(SubspaceTemplateModel(
AddSubSpaceModel(
SubspaceTemplateModel(
subspaceName: value.trim(),
disabled: false)));
textController.clear();
@ -130,6 +133,17 @@ class CreateSubSpaceModelDialog extends StatelessWidget {
color: ColorsManager.blackColor),
),
),
if (state.errorMessage.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Text(
state.errorMessage,
style: const TextStyle(
color: ColorsManager.warningRed,
fontSize: 12,
),
),
),
],
),
),
@ -165,7 +179,7 @@ class CreateSubSpaceModelDialog extends StatelessWidget {
],
),
),
);
));
},
),
),