mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
added white background color to container
This commit is contained in:
@ -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/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||||
import 'package:syncrow_web/utils/constants/action_enum.dart';
|
import 'package:syncrow_web/utils/constants/action_enum.dart';
|
||||||
|
|
||||||
// BLoC
|
|
||||||
class SubSpaceModelBloc extends Bloc<SubSpaceModelEvent, SubSpaceModelState> {
|
class SubSpaceModelBloc extends Bloc<SubSpaceModelEvent, SubSpaceModelState> {
|
||||||
SubSpaceModelBloc() : super(SubSpaceModelState([], [])) {
|
SubSpaceModelBloc() : super(SubSpaceModelState([], [], '')) {
|
||||||
|
// Handle AddSubSpaceModel Event
|
||||||
on<AddSubSpaceModel>((event, emit) {
|
on<AddSubSpaceModel>((event, emit) {
|
||||||
final updatedSubSpaces = List<SubspaceTemplateModel>.from(state.subSpaces)
|
// Check for duplicate names (case-insensitive)
|
||||||
..add(event.subSpace);
|
final existingNames =
|
||||||
emit(SubSpaceModelState(updatedSubSpaces, state.updatedSubSpaceModels));
|
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,
|
||||||
|
'', // Clear error message
|
||||||
|
));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle RemoveSubSpaceModel Event
|
||||||
on<RemoveSubSpaceModel>((event, emit) {
|
on<RemoveSubSpaceModel>((event, emit) {
|
||||||
final updatedSubSpaces = List<SubspaceTemplateModel>.from(state.subSpaces)
|
final updatedSubSpaces = List<SubspaceTemplateModel>.from(state.subSpaces)
|
||||||
..remove(event.subSpace);
|
..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) {
|
on<UpdateSubSpaceModel>((event, emit) {
|
||||||
final updatedSubSpaces = state.subSpaces.map((subSpace) {
|
final updatedSubSpaces = state.subSpaces.map((subSpace) {
|
||||||
if (subSpace.uuid == event.updatedSubSpace.uuid) {
|
if (subSpace.uuid == event.updatedSubSpace.uuid) {
|
||||||
@ -48,7 +74,11 @@ class SubSpaceModelBloc extends Bloc<SubSpaceModelEvent, SubSpaceModelState> {
|
|||||||
uuid: event.updatedSubSpace.uuid!,
|
uuid: event.updatedSubSpace.uuid!,
|
||||||
));
|
));
|
||||||
|
|
||||||
emit(SubSpaceModelState(updatedSubSpaces, updatedSubspaceModels));
|
emit(SubSpaceModelState(
|
||||||
|
updatedSubSpaces,
|
||||||
|
updatedSubspaceModels,
|
||||||
|
'', // Clear error message
|
||||||
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,23 @@ import 'package:syncrow_web/pages/spaces_management/space_model/models/space_tem
|
|||||||
class SubSpaceModelState {
|
class SubSpaceModelState {
|
||||||
final List<SubspaceTemplateModel> subSpaces;
|
final List<SubspaceTemplateModel> subSpaces;
|
||||||
final List<UpdateSubspaceTemplateModel> updatedSubSpaceModels;
|
final List<UpdateSubspaceTemplateModel> updatedSubSpaceModels;
|
||||||
|
final String errorMessage;
|
||||||
|
|
||||||
SubSpaceModelState(
|
SubSpaceModelState(
|
||||||
this.subSpaces,
|
this.subSpaces,
|
||||||
this.updatedSubSpaceModels,
|
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,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
),
|
),
|
||||||
child: ButtonContentWidget(
|
child: const ButtonContentWidget(
|
||||||
icon: Icons.add,
|
icon: Icons.add,
|
||||||
label: 'Add Devices',
|
label: 'Add Devices',
|
||||||
),
|
),
|
||||||
|
@ -41,131 +41,145 @@ class CreateSubSpaceModelDialog extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
child: BlocBuilder<SubSpaceModelBloc, SubSpaceModelState>(
|
child: BlocBuilder<SubSpaceModelBloc, SubSpaceModelState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return SizedBox(
|
return Container(
|
||||||
width: screenWidth * 0.35,
|
color: ColorsManager.whiteColors,
|
||||||
child: Padding(
|
child: SizedBox(
|
||||||
padding: const EdgeInsets.all(16.0),
|
width: screenWidth * 0.35,
|
||||||
child: Column(
|
child: Padding(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
padding: const EdgeInsets.all(16.0),
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
Text(
|
mainAxisSize: MainAxisSize.min,
|
||||||
dialogTitle,
|
children: [
|
||||||
style: Theme.of(context)
|
Text(
|
||||||
.textTheme
|
dialogTitle,
|
||||||
.headlineLarge
|
style: Theme.of(context)
|
||||||
?.copyWith(color: ColorsManager.blackColor),
|
.textTheme
|
||||||
),
|
.headlineLarge
|
||||||
const SizedBox(height: 16),
|
?.copyWith(color: ColorsManager.blackColor),
|
||||||
Container(
|
),
|
||||||
width: screenWidth * 0.35,
|
const SizedBox(height: 16),
|
||||||
padding: const EdgeInsets.symmetric(
|
Container(
|
||||||
vertical: 10.0, horizontal: 16.0),
|
width: screenWidth * 0.35,
|
||||||
decoration: BoxDecoration(
|
padding: const EdgeInsets.symmetric(
|
||||||
color: ColorsManager.boxColor,
|
vertical: 10.0, horizontal: 16.0),
|
||||||
borderRadius: BorderRadius.circular(10),
|
decoration: BoxDecoration(
|
||||||
),
|
color: ColorsManager.boxColor,
|
||||||
child: Wrap(
|
borderRadius: BorderRadius.circular(10),
|
||||||
spacing: 8.0,
|
),
|
||||||
runSpacing: 8.0,
|
child: Wrap(
|
||||||
children: [
|
spacing: 8.0,
|
||||||
...state.subSpaces.map(
|
runSpacing: 8.0,
|
||||||
(subSpace) => Chip(
|
children: [
|
||||||
label: Text(
|
...state.subSpaces.map(
|
||||||
subSpace.subspaceName,
|
(subSpace) => Chip(
|
||||||
style: const TextStyle(
|
label: Text(
|
||||||
color: ColorsManager.spaceColor),
|
subSpace.subspaceName,
|
||||||
),
|
style: const TextStyle(
|
||||||
backgroundColor: ColorsManager.whiteColors,
|
color: ColorsManager.spaceColor),
|
||||||
shape: RoundedRectangleBorder(
|
),
|
||||||
borderRadius: BorderRadius.circular(8),
|
backgroundColor: ColorsManager.whiteColors,
|
||||||
side: const BorderSide(
|
shape: RoundedRectangleBorder(
|
||||||
color: ColorsManager.transparentColor,
|
borderRadius: BorderRadius.circular(8),
|
||||||
width: 0,
|
side: const BorderSide(
|
||||||
|
color: ColorsManager.transparentColor,
|
||||||
|
width: 0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
deleteIcon: Container(
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(
|
||||||
|
color: ColorsManager.lightGrayColor,
|
||||||
|
width: 1.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.close,
|
||||||
|
size: 16,
|
||||||
|
color: ColorsManager.lightGrayColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onDeleted: () => context
|
||||||
|
.read<SubSpaceModelBloc>()
|
||||||
|
.add(RemoveSubSpaceModel(subSpace)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
deleteIcon: Container(
|
SizedBox(
|
||||||
width: 24,
|
width: 200,
|
||||||
height: 24,
|
child: TextField(
|
||||||
decoration: BoxDecoration(
|
controller: textController,
|
||||||
shape: BoxShape.circle,
|
decoration: InputDecoration(
|
||||||
border: Border.all(
|
border: InputBorder.none,
|
||||||
color: ColorsManager.lightGrayColor,
|
hintText: state.subSpaces.isEmpty
|
||||||
width: 1.5,
|
? 'Please enter the name'
|
||||||
|
: null,
|
||||||
|
hintStyle: const TextStyle(
|
||||||
|
color: ColorsManager.lightGrayColor),
|
||||||
|
),
|
||||||
|
onSubmitted: (value) {
|
||||||
|
if (value.trim().isNotEmpty) {
|
||||||
|
context.read<SubSpaceModelBloc>().add(
|
||||||
|
AddSubSpaceModel(
|
||||||
|
SubspaceTemplateModel(
|
||||||
|
subspaceName: value.trim(),
|
||||||
|
disabled: false)));
|
||||||
|
textController.clear();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
style: const TextStyle(
|
||||||
|
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,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: const Icon(
|
],
|
||||||
Icons.close,
|
|
||||||
size: 16,
|
|
||||||
color: ColorsManager.lightGrayColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onDeleted: () => context
|
|
||||||
.read<SubSpaceModelBloc>()
|
|
||||||
.add(RemoveSubSpaceModel(subSpace)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
width: 200,
|
|
||||||
child: TextField(
|
|
||||||
controller: textController,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
border: InputBorder.none,
|
|
||||||
hintText: state.subSpaces.isEmpty
|
|
||||||
? 'Please enter the name'
|
|
||||||
: null,
|
|
||||||
hintStyle: const TextStyle(
|
|
||||||
color: ColorsManager.lightGrayColor),
|
|
||||||
),
|
|
||||||
onSubmitted: (value) {
|
|
||||||
if (value.trim().isNotEmpty) {
|
|
||||||
context.read<SubSpaceModelBloc>().add(
|
|
||||||
AddSubSpaceModel(SubspaceTemplateModel(
|
|
||||||
subspaceName: value.trim(),
|
|
||||||
disabled: false)));
|
|
||||||
textController.clear();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
style: const TextStyle(
|
|
||||||
color: ColorsManager.blackColor),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: CancelButton(
|
|
||||||
label: 'Cancel',
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(height: 16),
|
||||||
Expanded(
|
Row(
|
||||||
child: DefaultButton(
|
children: [
|
||||||
onPressed: () {
|
Expanded(
|
||||||
final subSpaces = context
|
child: CancelButton(
|
||||||
.read<SubSpaceModelBloc>()
|
label: 'Cancel',
|
||||||
.state
|
onPressed: () {
|
||||||
.subSpaces;
|
Navigator.of(context).pop();
|
||||||
Navigator.of(context).pop(subSpaces);
|
},
|
||||||
},
|
),
|
||||||
backgroundColor: ColorsManager.secondaryColor,
|
),
|
||||||
borderRadius: 10,
|
const SizedBox(width: 10),
|
||||||
foregroundColor: ColorsManager.whiteColors,
|
Expanded(
|
||||||
child: const Text('OK'),
|
child: DefaultButton(
|
||||||
),
|
onPressed: () {
|
||||||
|
final subSpaces = context
|
||||||
|
.read<SubSpaceModelBloc>()
|
||||||
|
.state
|
||||||
|
.subSpaces;
|
||||||
|
Navigator.of(context).pop(subSpaces);
|
||||||
|
},
|
||||||
|
backgroundColor: ColorsManager.secondaryColor,
|
||||||
|
borderRadius: 10,
|
||||||
|
foregroundColor: ColorsManager.whiteColors,
|
||||||
|
child: const Text('OK'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
));
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user