resolveViewport method
Viewport dimensions without a hit-test. Safe on Dart 3.12 / iOS 26 where
HitTestResult is inaccessible in the CFE eval scope; use over resolve.
Implementation
Future<({double dpr, double w, double h})> resolveViewport(Scene scene, String glintId) async {
final node = scene.findByGlintId(glintId);
if (node == null) {
throw GeometryResolveError('unknown glintId: $glintId');
}
try {
await _runtime.setInspectorSelection(
inspectorId: node.inspectorId,
groupName: scene.groupName,
);
} on RuntimeStaleInspectorIdError catch (e) {
throw StaleInspectorIdError('setSelectionById(${node.inspectorId}) failed: $e');
} on Object catch (e) {
throw GeometryResolveError(
'setSelectionById(${node.inspectorId}) failed: $e',
);
}
final String? json;
try {
json = await _runtime.evaluateString(GeometryExpr.buildViewProbe(), rethrowErrors: true);
} on RuntimeEvalError catch (e) {
throw GeometryResolveError('evaluate(viewProbe) failed: ${e.message}');
}
if (json == null) {
throw GeometryResolveError('evaluate(viewProbe) returned non-string');
}
final decoded = _decode(json, 'viewProbe');
return (
dpr: (decoded['dpr'] as num).toDouble(),
w: (decoded['vw'] as num).toDouble(),
h: (decoded['vh'] as num).toDouble(),
);
}