genUiRenderedSemantics function
The meaningful semantics of what is currently on screen.
The no-argument form of genUiSemantics, for a test that has just pumped a widget and turned semantics on. Reads the view's own tree rather than a node the caller has to dig out of the binding.
final handle = tester.ensureSemantics();
await tester.pumpWidget(...);
await tester.pumpAndSettle();
final nodes = genUiRenderedSemantics();
handle.dispose();
Throws a StateError when semantics are off, which in a widget test means
tester.ensureSemantics() was not called.
Implementation
List<GenUiSemanticNode> genUiRenderedSemantics() {
for (final RenderView view in RendererBinding.instance.renderViews) {
final SemanticsNode? root = view.owner?.semanticsOwner?.rootSemanticsNode;
if (root != null) return genUiSemantics(root);
}
throw StateError(
'No semantics tree was built. In a widget test, call '
'`tester.ensureSemantics()` before pumping, and dispose the handle '
'afterwards.',
);
}