deselect on outside

This commit is contained in:
hannathkadher
2024-11-21 21:05:49 +04:00
parent 278d39cca1
commit 8b7de7c8fd
2 changed files with 44 additions and 14 deletions

View File

@ -4,7 +4,6 @@ import 'package:syncrow_web/pages/common/text_field/custom_text_field.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_managment_bloc.dart';
import 'package:syncrow_web/pages/common/buttons/search_reset_buttons.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
import 'package:syncrow_web/utils/style.dart';
class DeviceSearchFilters extends StatefulWidget {
const DeviceSearchFilters({super.key});

View File

@ -94,10 +94,13 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
@override
Widget build(BuildContext context) {
final visibleSpaces = flattenSpaces(widget.spaces);
final visibleConnections = createConnections(widget.spaces);
Size screenSize = MediaQuery.of(context).size;
return Expanded(
child: GestureDetector(
onTap: () {
_deselectSpace();
},
child: Container(
decoration: const BoxDecoration(
border: Border(
@ -147,17 +150,22 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
_updateNodePosition(entry.value, newPosition);
},
buildSpaceContainer: (int index) {
return SpaceContainerWidget(
index: index,
onDoubleTap: () {
_showEditSpaceDialog(visibleSpaces[index]);
},
onTap: () {
_selectSpace(visibleSpaces[index]);
},
icon: visibleSpaces[index].icon ?? '',
name: visibleSpaces[index].name,
);
final bool isHighlighted =
_isHighlightedSpace(visibleSpaces[index]);
return Opacity(
opacity: isHighlighted ? 1.0 : 0.3,
child: SpaceContainerWidget(
index: index,
onDoubleTap: () {
_showEditSpaceDialog(visibleSpaces[index]);
},
onTap: () {
_selectSpace(visibleSpaces[index]);
},
icon: visibleSpaces[index].icon ?? '',
name: visibleSpaces[index].name,
));
},
),
),
@ -178,7 +186,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
],
),
),
);
));
}
Widget _buildHeader() {
@ -570,4 +578,27 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
widget.onSpaceSelected!(space);
}
}
bool _isHighlightedSpace(SpaceModel space) {
if (widget.selectedSpace == null) return true;
if (space == widget.selectedSpace) return true;
if (widget.selectedSpace?.parent?.name == space.name &&
widget.selectedSpace?.parent?.position == space.position) return true;
if (widget.selectedSpace?.children.contains(space) == true) return true;
return false; // Otherwise, reduce opacity
}
void _deselectSpace() {
if (widget.selectedSpace != null) {
setState(() {
widget.selectedSpace = null;
});
if (widget.onSpaceSelected != null) {
widget.onSpaceSelected!(null); // Notify parent that no space is selected
}
}
}
}