evaluate method
Evaluates expression in a library with the Flutter widgets API in scope (framework first, then the app's own).
Returns the raw InstanceRef for the caller to crack open by type.
Throws RuntimeEvalError on compilation error or ErrorRef return.
Implementation
@override
Future<InstanceRef> evaluate(String expression) async {
final library = await _evalLibrary();
final Object raw;
try {
raw = await _guard(
() async => _vm.service.evaluate(
flutterIsolateId, _evalLibIsolateId == flutterIsolateId ? library : await _evalLibrary(), expression),
op: 'evaluate',
timeout: _evaluateLimit,
);
} on RPCError catch (e) {
// Code 113 = expression compilation error (e.g. platform view context).
// Wrap as RuntimeEvalError so callers get a typed, structured failure.
throw RuntimeEvalError(expression, 'RPCError(${e.code}): ${e.message}${_compilerDetail(e)}');
}
if (raw is InstanceRef) return raw;
if (raw is ErrorRef) {
throw RuntimeEvalError(expression, raw.message ?? 'ErrorRef');
}
throw RuntimeEvalError(
expression,
'unexpected eval return ${raw.runtimeType}',
);
}