compute_drag_target_in_virtualized_list.dart

void determineDragPosition(BuildContext itemContext, DragUpdateDetails details, Item draggedItem, double itemHeight) { _dragOperation.offset.value = details.globalPosition; // Find the fixed extent list renderer. RenderSliverFixedExtentList extentList; for (var p = itemContext.findRenderObject(); p != null; p = p is RenderObject ? p.parent as RenderObject : null) { if (p is RenderSliverFixedExtentList) { extentList = p; break; } } if (extentList == null) { // We failed. return; } // We've got an extent list. Get the first child and find its top. var first = extentList.firstChild; // Compute the scroll offset of the first visible item (N.B. this is not // the first item in the list, it's the first one that's probably // visible). var offsetOfFirst = extentList.childScrollOffset(first); // We know this item's in the tree, so we can call globalToLocal on it. var local = first.globalToLocal(details.globalPosition); // Now we know where our cursor is relative to the first visible item. var y = offsetOfFirst + local.dy; // Compute index of item the cursor is over. var index = (y / itemHeight).floor(); // Compute offset over that row (how close are we to the top of the row // we're hovering). var localOffset = y % itemHeight; // Use index to compute drop target. var dropTarget = index >= 0 && index < _flat.length ? _flat[index] : null; // Drop logic goes here }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.