comment (SpaceModelLinking && Or)Widgets cuz no need for spaceModel for now&& fix the delete devices from subSpaces to keep in main space not to get deleted

This commit is contained in:
raf-dev1
2025-06-10 15:11:33 +03:00
parent 08a9a5c71f
commit 692c9e7792

View File

@ -155,63 +155,76 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
}, },
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
SpaceModelLinkingWidget( // SpaceModelLinkingWidget(
isSpaceModelDisabled: isSpaceModelDisabled, // isSpaceModelDisabled: true,
onPressed: () { // // isSpaceModelDisabled,
isSpaceModelDisabled // onPressed: () {
? null // isSpaceModelDisabled
: _showLinkSpaceModelDialog(context); // ? null
}, // : _showLinkSpaceModelDialog(context);
onDeleted: () => setState(() { // },
selectedSpaceModel = null; // onDeleted: () => setState(() {
subspaces = widget.subspaces ?? []; // selectedSpaceModel = null;
tags = widget.tags ?? []; // subspaces = widget.subspaces ?? [];
}), // tags = widget.tags ?? [];
screenWidth: screenWidth, // }),
selectedSpaceModel: selectedSpaceModel, // screenWidth: screenWidth,
), // selectedSpaceModel: selectedSpaceModel,
// ),
const SizedBox(height: 25), const SizedBox(height: 25),
Row( // Row(
children: [ // children: [
const Expanded( // const Expanded(
child: Divider( // child: Divider(
color: ColorsManager.neutralGray, // color: ColorsManager.neutralGray,
thickness: 1.0, // thickness: 1.0,
), // ),
), // ),
Padding( // Padding(
padding: const EdgeInsets.symmetric(horizontal: 6.0), // padding: const EdgeInsets.symmetric(horizontal: 6.0),
child: Text( // child: Text(
'OR', // 'OR',
style: Theme.of(context) // style: Theme.of(context)
.textTheme // .textTheme
.bodyMedium // .bodyMedium
?.copyWith(fontWeight: FontWeight.bold), // ?.copyWith(fontWeight: FontWeight.bold),
), // ),
), // ),
const Expanded( // const Expanded(
child: Divider( // child: Divider(
color: ColorsManager.neutralGray, // color: ColorsManager.neutralGray,
thickness: 1.0, // thickness: 1.0,
), // ),
), // ),
], // ],
), // ),
const SizedBox(height: 25), const SizedBox(height: 25),
SubSpacePartWidget( SubSpacePartWidget(
subspaces: subspaces, subspaces: subspaces,
onPressed: () { onPressed: () {
isTagsAndSubspaceModelDisabled isTagsAndSubspaceModelDisabled
? null ? null
: _showSubSpaceDialog(context, enteredName, [], : _showSubSpaceDialog(
false, widget.products, subspaces); context,
enteredName,
[],
false,
widget.products,
subspaces,
);
}, },
isTagsAndSubspaceModelDisabled: isTagsAndSubspaceModelDisabled:
isTagsAndSubspaceModelDisabled, isTagsAndSubspaceModelDisabled,
screenWidth: screenWidth, screenWidth: screenWidth,
editChipOnTap: () async { editChipOnTap: () async {
_showSubSpaceDialog(context, enteredName, [], true, _showSubSpaceDialog(
widget.products, subspaces); context,
enteredName,
[],
true,
widget.products,
subspaces,
);
}, },
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
@ -289,6 +302,13 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
? enteredName ? enteredName
: (widget.name ?? ''); : (widget.name ?? '');
if (newName.isNotEmpty) { if (newName.isNotEmpty) {
if (tags != null && tags!.isNotEmpty) {
if (tags!.any(
(tag) => tag.uuid == null || tag.uuid!.isEmpty,
)) {
return;
}
}
widget.onCreateSpace( widget.onCreateSpace(
newName, newName,
selectedIcon, selectedIcon,
@ -352,12 +372,13 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
} }
void _showSubSpaceDialog( void _showSubSpaceDialog(
BuildContext context, BuildContext context,
String name, String name,
final List<Tag>? spaceTags, final List<Tag>? spaceTags,
bool isEdit, bool isEdit,
List<ProductModel>? products, List<ProductModel>? products,
final List<SubspaceModel>? existingSubSpaces) { final List<SubspaceModel>? existingSubSpaces,
) {
showDialog( showDialog(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
@ -366,7 +387,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
dialogTitle: isEdit ? 'Edit Sub-spaces' : 'Create Sub-spaces', dialogTitle: isEdit ? 'Edit Sub-spaces' : 'Create Sub-spaces',
products: products, products: products,
existingSubSpaces: existingSubSpaces, existingSubSpaces: existingSubSpaces,
onSave: (slectedSubspaces) { onSave: (slectedSubspaces, updatedSubSpaces) {
final List<Tag> tagsToAppendToSpace = []; final List<Tag> tagsToAppendToSpace = [];
if (slectedSubspaces != null && slectedSubspaces.isNotEmpty) { if (slectedSubspaces != null && slectedSubspaces.isNotEmpty) {
@ -378,6 +399,22 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
.toList(); .toList();
for (var s in deletedSubspaces) { for (var s in deletedSubspaces) {
if (s.tags != null) { if (s.tags != null) {
s.tags!.forEach(
(tag) => tag.location = null,
);
tagsToAppendToSpace.addAll(s.tags!);
}
}
}
} else {
if (existingSubSpaces != null) {
final deletedSubspaces = existingSubSpaces;
for (var s in deletedSubspaces) {
if (s.tags != null) {
s.tags!.forEach(
(tag) => tag.location = null,
);
tagsToAppendToSpace.addAll(s.tags!); tagsToAppendToSpace.addAll(s.tags!);
} }
} }