findTextInComponent static method

AttributedText findTextInComponent(
  1. String nodeId, [
  2. Finder? superEditorFinder
])

Returns the AttributedText within the ParagraphNode associated with the given nodeId.

There must be a ParagraphNode with the given nodeId, displayed in a SuperEditor.

By default, this method expects a single SuperEditor in the widget tree and finds it byType. To specify one SuperEditor among many, pass a superEditorFinder.

Implementation

static AttributedText findTextInComponent(String nodeId, [Finder? superEditorFinder]) {
  final documentLayout = findDocumentLayout(superEditorFinder);
  final component = documentLayout.getComponentByNodeId(nodeId);

  if (component is TextComponentState) {
    return component.widget.text;
  }

  if (component is ProxyDocumentComponent) {
    return (component.childDocumentComponentKey.currentState as TextComponentState).widget.text;
  }

  throw Exception('The component for node id $nodeId is not a TextComponent.');
}