getNodeAt<NodeType extends DocumentNode> static method
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.nodes.length) {
throw Exception('Tried to access index $index in a document where the max index is ${doc.nodes.length - 1}');
}
final node = doc.nodes[index];
if (node is! NodeType) {
throw Exception('Tried to access a ${node.runtimeType} as $NodeType');
}
return node;
}