getNodeAt<NodeType extends DocumentNode> static method

NodeType getNodeAt<NodeType extends DocumentNode>(
  1. int index, [
  2. Finder? superEditorFinder
])

Returns the DocumentNode at given the index.

The given index must be a valid node index inside the Document.The node at index must be of type NodeType.

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 NodeType getNodeAt<NodeType extends DocumentNode>(int index, [Finder? superEditorFinder]) {
  final doc = findDocument(superEditorFinder);

  if (doc == null) {
    throw Exception('SuperEditor not found');
  }

  if (index >= doc.nodeCount) {
    throw Exception('Tried to access index $index in a document where the max index is ${doc.nodeCount - 1}');
  }

  final node = doc.getNodeAt(index);
  if (node is! NodeType) {
    throw Exception('Tried to access a ${node.runtimeType} as $NodeType');
  }

  return node;
}