removeLinkById method
This method is used to remove a link by its ID.
Emits a RemoveLinkEvent event.
Implementation
void removeLinkById(
String id, {
String? eventId,
bool isHandled = false,
}) {
if (!linksById.containsKey(id)) return;
final link = linksById[id]!;
// Remove the link from its associated ports
final fromPort = nodes[link.fromTo.from]?.ports[link.fromTo.to];
final toPort = nodes[link.fromTo.fromPort]?.ports[link.fromTo.toPort];
fromPort?.links.remove(link);
toPort?.links.remove(link);
linksById.remove(id);
// selectedLinkIds.remove(id); We don't remove the link from the selected links because you might be iterating over them.
linksDataDirty = true;
eventBus.emit(
RemoveLinkEvent(
id: eventId ?? const Uuid().v4(),
link,
isHandled: isHandled,
),
);
}