getVariable method

dynamic getVariable(
  1. String name
)

Retrieves the value of a variable from the current scope or any parent scopes.

This method searches the variable stack from the top (most recent scope) to the bottom (global scope) to find the first occurrence of the specified variable name. If the variable is found, its value is returned. If the variable is not found, null is returned.

name The name of the variable to retrieve. return The value of the variable, or null if the variable is not found.

Implementation

dynamic getVariable(String name) {
  // Iterate from the top of the stack (most recent scope) to the bottom (global scope)
  for (var i = _variableStack.length - 1; i >= 0; i--) {
    if (_variableStack[i].containsKey(name)) {
      return _variableStack[i][name];
    }
  }
  return null;
}