The runtime overrides system allows you to dynamically swap function or constructor implementations at runtime.
1. Prepare the code for overriding
In your Dart code, wrap the call site with a null-coalescing call to runtimeOverride() using a unique ID:
final result = runtimeOverride('#myFunction') ?? myFunction();
Note: You may need to cast the return value of runtimeOverride as the compiler cannot specify generic parameters to the Dart type system.
2. Mark the override in eval code
In the code being evaluated, mark the target function with the @RuntimeOverride annotation:
@RuntimeOverride('#myFunction')
String myFunction() => 'Updated version of string';
3. Load overrides
Call loadGlobalOverrides() on the Runtime instance. This sets the runtime as the single global runtime and loads overrides for use by hot wrappers.
void main() {
// Give the override a unique ID
final result = runtimeOverride('#myFunction') ?? myFunction();
print(result);
}
String myFunction() => 'Original version of string';
// In the eval code:
@RuntimeOverride('#myFunction')
String myFunction() => 'Updated version of string';