mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-25 15:29:40 +00:00
Enhance DragTarget logic in CommunityStructureCanvas by refining conditions for rendering and improving readability. Ensure proper handling of dragged data and its parent/community relationships.
This commit is contained in:
@ -425,17 +425,29 @@ class _CommunityStructureCanvasState extends State<CommunityStructureCanvas>
|
|||||||
height: _cardHeight,
|
height: _cardHeight,
|
||||||
child: DragTarget<SpaceReorderDataModel>(
|
child: DragTarget<SpaceReorderDataModel>(
|
||||||
builder: (context, candidateData, rejectedData) {
|
builder: (context, candidateData, rejectedData) {
|
||||||
if (_draggedData == null) return const SizedBox.shrink();
|
if (_draggedData == null) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
final isTargetForDragged = (_draggedData?.parent?.uuid == parent?.uuid &&
|
final children = parent?.children ?? community?.spaces ?? [];
|
||||||
_draggedData?.community == null) ||
|
final isSameParent = (_draggedData!.parent?.uuid == parent?.uuid &&
|
||||||
(_draggedData?.community?.uuid == community?.uuid &&
|
_draggedData!.community == null) ||
|
||||||
_draggedData?.parent == null);
|
(_draggedData!.community?.uuid == community?.uuid &&
|
||||||
|
_draggedData!.parent == null);
|
||||||
|
|
||||||
if (!isTargetForDragged) return const SizedBox.shrink();
|
if (!isSameParent) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
final oldIndex =
|
||||||
|
children.indexWhere((s) => s.uuid == _draggedData!.space.uuid);
|
||||||
|
if (oldIndex != -1 && (oldIndex == index || oldIndex == index - 1)) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
width: 40,
|
width: 40,
|
||||||
|
alignment: Alignment.center,
|
||||||
height: _cardHeight,
|
height: _cardHeight,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: context.theme.colorScheme.primary.withValues(
|
color: context.theme.colorScheme.primary.withValues(
|
||||||
@ -462,6 +474,9 @@ class _CommunityStructureCanvasState extends State<CommunityStructureCanvas>
|
|||||||
|
|
||||||
final oldIndex =
|
final oldIndex =
|
||||||
children.indexWhere((s) => s.uuid == data.data.space.uuid);
|
children.indexWhere((s) => s.uuid == data.data.space.uuid);
|
||||||
|
if (oldIndex == -1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (oldIndex == index || oldIndex == index - 1) {
|
if (oldIndex == index || oldIndex == index - 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user