GlobalGetter class

A wrapper for lazy-evaluated global getters with optional setter support.

When a GlobalGetter is stored in the environment and accessed via Environment.get, the getter function is invoked and the result is returned. This enables lazy evaluation of global variables that may not be initialized at registration time.

If a setter is provided, the GlobalGetter also supports assignment. When assigned to via Environment.assign, the setter function is called instead of replacing the wrapper in the environment.

Example:

// Read-only global getter
environment.define('vscode', GlobalGetter(() => VSCode.instance));

// Global getter with setter support
int _counter = 0;
environment.define('counter', GlobalGetter(
  () => _counter,
  setter: (value) => _counter = value as int,
));

Constructors

GlobalGetter(Object? getter(), {void setter(Object? value)?})
Creates a new global getter wrapper.

Properties

getter Object? Function()
The getter function that returns the value when called.
final
hashCode int
The hash code for this object.
no setterinherited
hasSetter bool
Whether this global getter supports assignment.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
setter → void Function(Object? value)?
Optional setter function for assignment support. If null, assignment to this global is not supported.
final

Methods

call() Object?
Calls the getter and returns the result.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited