getNextNode method
Gets the next node based on the current node and action.
This method implements Python's action-based transition logic.
Logic:
- If
actionis a String, it looks for a successor with that key. - If
actionis not a String (e.g., null), it looks for 'default'. - If no successor is found for the determined key, the flow ends.
Implementation
BaseNode? getNextNode(BaseNode curr, dynamic action) {
BaseNode? next;
// Determine the key to look for in the successors map.
// If action is a string, use it. Otherwise, use 'default'.
final actionToFind = (action is String) ? action : 'default';
if (curr.successors.containsKey(actionToFind)) {
next = curr.successors[actionToFind];
} else {
next = null; // No successor found for the action.
}
// Log a warning if the flow terminates but other paths were available.
// This is useful for debugging and mirrors Python's behavior.
if (next == null && curr.successors.isNotEmpty) {
// We only log if the specific action we were looking for was not found.
if (!curr.successors.containsKey(actionToFind)) {
curr.log(
"Warning: Flow ends: '$action' not found in "
'${curr.successors.keys.toList()}',
);
}
}
return next;
}