create method

Variable<T> create(
  1. String name, {
  2. T? value,
  3. bool? constant,
})

Create a new variable within this scope.

You may optionally provide a value, or mark the variable as constant.

Implementation

Variable<T> create(String name, {T? value, bool? constant}) {
  // Check if it exists first.
  if (_variables.any((v) => v.name == name)) {
    throw StateError(
        'A symbol named "$name" already exists within the current context.');
  }

  _wipeLookupCache(name);
  var v = Variable<T>._(name, this, value: value);
  if (constant == true) v.lock();
  _variables.add(v);
  return v;
}