createSession method
Creates a drag session for managing drag operation lifecycle.
The session automatically handles canvas locking/unlocking. Elements
just need to call lifecycle methods: start, end, cancel.
Only one session can be active at a time. Creating a new session while one is active will cancel the existing session first.
Example:
DragSession? _session;
void _handleDragStart(details) {
_originalPosition = node.position.value; // Capture state
_session = controller.createSession(DragSessionType.nodeDrag);
_session!.start(); // Locks canvas
}
void _handleDragEnd(details) {
_session?.end(); // Unlocks canvas
_session = null;
}
void _handleDragCancel() {
_session?.cancel(); // Unlocks canvas
_session = null;
node.position.value = _originalPosition!; // Restore state
}
Implementation
DragSession createSession(DragSessionType type) {
// Cancel any existing active session
_activeSession?.cancel();
// Create new session
_activeSession = _DragSessionImpl(type, interaction, _onSessionEnded);
return _activeSession!;
}