updated deselect on structure

This commit is contained in:
hannathkadher
2024-11-28 20:01:14 +04:00
parent 660b5aaf6c
commit 817671dbeb

View File

@ -52,7 +52,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
void initState() { void initState() {
super.initState(); super.initState();
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : []; spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : []; connections =
widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
_adjustCanvasSizeForSpaces(); _adjustCanvasSizeForSpaces();
_nameController = TextEditingController( _nameController = TextEditingController(
text: widget.selectedCommunity?.name ?? '', text: widget.selectedCommunity?.name ?? '',
@ -79,12 +80,14 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
if (oldWidget.spaces != widget.spaces) { if (oldWidget.spaces != widget.spaces) {
setState(() { setState(() {
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : []; spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : []; connections =
widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
_adjustCanvasSizeForSpaces(); _adjustCanvasSizeForSpaces();
}); });
} }
if (widget.selectedSpace != oldWidget.selectedSpace && widget.selectedSpace != null) { if (widget.selectedSpace != oldWidget.selectedSpace &&
widget.selectedSpace != null) {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
_moveToSpace(widget.selectedSpace!); _moveToSpace(widget.selectedSpace!);
}); });
@ -101,7 +104,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
return Expanded( return Expanded(
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
_deselectSpace(); _deselectSpace(context);
}, },
child: Container( child: Container(
decoration: const BoxDecoration( decoration: const BoxDecoration(
@ -156,9 +159,11 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
children: [ children: [
for (var connection in connections) for (var connection in connections)
Opacity( Opacity(
opacity: opacity: _isHighlightedConnection(connection)
_isHighlightedConnection(connection) ? 1.0 : 0.3, // Adjust opacity ? 1.0
child: CustomPaint(painter: CurvedLinePainter([connection])), : 0.3, // Adjust opacity
child: CustomPaint(
painter: CurvedLinePainter([connection])),
), ),
for (var entry in spaces.asMap().entries) for (var entry in spaces.asMap().entries)
if (entry.value.status != SpaceStatus.deleted) if (entry.value.status != SpaceStatus.deleted)
@ -167,10 +172,12 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
top: entry.value.position.dy, top: entry.value.position.dy,
child: SpaceCardWidget( child: SpaceCardWidget(
index: entry.key, index: entry.key,
onButtonTap: (int index, Offset newPosition, String direction) { onButtonTap: (int index, Offset newPosition,
String direction) {
_showCreateSpaceDialog( _showCreateSpaceDialog(
screenSize, screenSize,
position: spaces[index].position + newPosition, position:
spaces[index].position + newPosition,
parentIndex: index, parentIndex: index,
direction: direction, direction: direction,
); );
@ -183,7 +190,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
_updateNodePosition(entry.value, newPosition); _updateNodePosition(entry.value, newPosition);
}, },
buildSpaceContainer: (int index) { buildSpaceContainer: (int index) {
final bool isHighlighted = _isHighlightedSpace(spaces[index]); final bool isHighlighted =
_isHighlightedSpace(spaces[index]);
return Opacity( return Opacity(
opacity: isHighlighted ? 1.0 : 0.3, opacity: isHighlighted ? 1.0 : 0.3,
@ -193,7 +201,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
_showEditSpaceDialog(spaces[index]); _showEditSpaceDialog(spaces[index]);
}, },
onTap: () { onTap: () {
_selectSpace(spaces[index]); _selectSpace(context, spaces[index]);
}, },
icon: spaces[index].icon ?? '', icon: spaces[index].icon ?? '',
name: spaces[index].name, name: spaces[index].name,
@ -210,7 +218,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
child: AddSpaceButton( child: AddSpaceButton(
onTap: () { onTap: () {
_showCreateSpaceDialog(screenSize, _showCreateSpaceDialog(screenSize,
canvasHeight: canvasHeight, canvasWidth: canvasWidth); canvasHeight: canvasHeight,
canvasWidth: canvasWidth);
}, },
), ),
), ),
@ -270,12 +279,14 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
builder: (BuildContext context) { builder: (BuildContext context) {
return CreateSpaceDialog( return CreateSpaceDialog(
products: widget.products, products: widget.products,
parentSpace: parentIndex != null? spaces[parentIndex] : null, parentSpace: parentIndex != null ? spaces[parentIndex] : null,
onCreateSpace: (String name, String icon, List<SelectedProduct> selectedProducts) { onCreateSpace: (String name, String icon,
List<SelectedProduct> selectedProducts) {
setState(() { setState(() {
// Set the first space in the center or use passed position // Set the first space in the center or use passed position
Offset centerPosition = position ?? _getCenterPosition(screenSize); Offset centerPosition =
position ?? _getCenterPosition(screenSize);
SpaceModel newSpace = SpaceModel( SpaceModel newSpace = SpaceModel(
name: name, name: name,
icon: icon, icon: icon,
@ -319,7 +330,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
icon: space.icon, icon: space.icon,
isEdit: true, isEdit: true,
selectedProducts: space.selectedProducts, selectedProducts: space.selectedProducts,
onCreateSpace: (String name, String icon, List<SelectedProduct> selectedProducts) { onCreateSpace: (String name, String icon,
List<SelectedProduct> selectedProducts) {
setState(() { setState(() {
// Update the space's properties // Update the space's properties
space.name = name; space.name = name;
@ -331,8 +343,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
} }
}); });
}, },
// Pre-fill the dialog with current space data key: Key(space.name),
key: Key(space.name), // Add a unique key to ensure dialog refresh
); );
}, },
); );
@ -465,20 +476,19 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
..scale(1.2); ..scale(1.2);
} }
void _selectSpace(SpaceModel space) { void _selectSpace(BuildContext context, SpaceModel space) {
setState(() { context.read<SpaceManagementBloc>().add(
widget.selectedSpace = space; SelectSpaceEvent(
}); selectedCommunity: widget.selectedCommunity,
selectedSpace: space),
if (widget.onSpaceSelected != null) { );
widget.onSpaceSelected!(space);
}
} }
bool _isHighlightedSpace(SpaceModel space) { bool _isHighlightedSpace(SpaceModel space) {
if (widget.selectedSpace == null) return true; if (widget.selectedSpace == null) return true;
if (space == widget.selectedSpace) return true; if (space == widget.selectedSpace) return true;
if (widget.selectedSpace?.parent?.internalId == space.internalId) return true; if (widget.selectedSpace?.parent?.internalId == space.internalId)
return true;
if (widget.selectedSpace?.children != null) { if (widget.selectedSpace?.children != null) {
for (var child in widget.selectedSpace!.children) { for (var child in widget.selectedSpace!.children) {
if (child.internalId == space.internalId) { if (child.internalId == space.internalId) {
@ -489,16 +499,11 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
return false; return false;
} }
void _deselectSpace() { void _deselectSpace(BuildContext context) {
if (widget.selectedSpace != null) { context.read<SpaceManagementBloc>().add(
setState(() { SelectSpaceEvent(
widget.selectedSpace = null; selectedCommunity: widget.selectedCommunity, selectedSpace: null),
}); );
if (widget.onSpaceSelected != null) {
widget.onSpaceSelected!(null); // Notify parent that no space is selected
}
}
} }
bool _isHighlightedConnection(Connection connection) { bool _isHighlightedConnection(Connection connection) {