Document class abstract

A read-only document with styled text and multimedia elements.

A Document is comprised of a list of DocumentNodes, which describe the type and substance of a piece of content within the document. For example, a ParagraphNode holds a single paragraph of text within the document.

New types of content can be added by subclassing DocumentNode.

To represent a specific location within a Document, see DocumentPosition.

A Document has no opinion on the visual presentation of its content.

To edit the content of a document, see DocumentEditor.

Implemented types
Implementers
Available extensions

Constructors

Document()

Properties

first DocumentNode
The first element.
no setterinherited
firstOrNull DocumentNode?
Returns the first DocumentNode in this Document, or null if this Document is empty.
no setter
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Returns true if this Document has zero nodes, or false if it has `1+ nodes.
no setteroverride
isNotEmpty bool
Whether this collection has at least one element.
no setterinherited
iterator Iterator<DocumentNode>
A new Iterator that allows iterating the elements of this Iterable.
no setterinherited
last DocumentNode
The last element.
no setterinherited
lastOrNull DocumentNode?
Returns the last DocumentNode in this Document, or null if this Document is empty.
no setter
length int
The number of elements in this Iterable.
no setterinherited
nodeCount int
The number of DocumentNodes in this Document.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single DocumentNode
Checks that this iterable has only one element, and returns that element.
no setterinherited

Methods

addListener(DocumentChangeListener listener) → void
any(bool test(DocumentNode element)) bool
Checks whether any element of this iterable satisfies test.
inherited
cast<R>() Iterable<R>
A view of this iterable as an iterable of R instances.
inherited
contains(Object? element) bool
Whether the collection contains an element equal to element.
inherited
doesSelectedTextContainAttributions(DocumentSelection selection, Set<Attribution> attributions) bool

Available on Document, provided by the DocumentSelectionWithText extension

Returns true if all the text within the given selection contains at least some characters with each of the given attributions.
doesSelectionContainPosition(DocumentSelection selection, DocumentPosition position) bool

Available on Document, provided by the InspectDocumentSelection extension

Returns true if, and only if, the given position sits within the given selection in this Document.
elementAt(int index) DocumentNode
Returns the indexth element.
inherited
every(bool test(DocumentNode element)) bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Iterable<T> toElements(DocumentNode element)) Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
firstWhere(bool test(DocumentNode element), {DocumentNode orElse()?}) DocumentNode
The first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, T combine(T previousValue, DocumentNode element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<DocumentNode> other) Iterable<DocumentNode>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(DocumentNode element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
getAffinityBetween({required DocumentPosition base, required DocumentPosition extent}) TextAffinity

Available on Document, provided by the InspectDocumentAffinity extension

Returns the affinity direction implied by the given base and extent.
getAffinityBetweenNodes(DocumentNode base, DocumentNode extent) TextAffinity

Available on Document, provided by the InspectDocumentAffinity extension

getAffinityForRange(DocumentRange range) TextAffinity

Available on Document, provided by the InspectDocumentAffinity extension

getAffinityForSelection(DocumentSelection selection) TextAffinity

Available on Document, provided by the InspectDocumentAffinity extension

getAllAttributions(DocumentSelection selection) Set<Attribution>

Available on Document, provided by the DocumentSelectionWithText extension

Returns all attributions that appear throughout the entirety of the selected range.
getAttributionsByType<T>(DocumentSelection selection) Set<T>

Available on Document, provided by the DocumentSelectionWithText extension

Returns all attributions of type T that appear throughout the entirety of the selected range.
getNode(DocumentPosition position) DocumentNode?
Returns the DocumentNode at the given position, or null if no such node exists in this Document.
getNodeAfter(DocumentNode node) DocumentNode?
Returns the DocumentNode that appears immediately after the given node in this Document, or null if the given node is the last node, or the given node does not exist in this Document.
getNodeAfterById(String nodeId) DocumentNode?
Returns the DocumentNode that appears immediately after the node with the given nodeId in this Document, or null if the matching node is the last node in the document, or no such node exists.
getNodeAt(int index) DocumentNode?
Returns the DocumentNode at the given index, or null if no such node exists.
getNodeBefore(DocumentNode node) DocumentNode?
Returns the DocumentNode that appears immediately before the given node in this Document, or null if the given node is the first node, or the given node does not exist in this Document.
getNodeBeforeById(String nodeId) DocumentNode?
Returns the DocumentNode that appears immediately before the node with the given nodeId in this Document, or null if the matching node is the first node in the document, or no such node exists.
getNodeById(String nodeId) DocumentNode?
Returns the DocumentNode with the given nodeId, or null if no such node exists.
getNodeIndex(DocumentNode node) int
Returns the index of the given node, or -1 if the node does not exist within this Document.
getNodeIndexById(String nodeId) int
Returns the index of the DocumentNode in this Document that has the given nodeId, or -1 if the node does not exist.
getNodesInContentOrder(DocumentSelection selection) List<DocumentNode>

Available on Document, provided by the InspectDocumentSelection extension

Returns a list of all the DocumentNodes within the given selection, ordered from upstream to downstream.
getNodesInside(DocumentPosition position1, DocumentPosition position2) List<DocumentNode>
Returns all DocumentNodes from position1 to position2, including the nodes at position1 and position2.
getRangeBetween(DocumentPosition position1, DocumentPosition position2) DocumentRange

Available on Document, provided by the InspectDocumentRange extension

Returns a DocumentRange that ranges from position1 to position2, including position1 and position2.
hasEquivalentContent(Document other) bool
Returns true if the content in the other document is equivalent to the content in this document, ignoring any details that are unrelated to content, such as individual node IDs.
join([String separator = ""]) String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(DocumentNode element), {DocumentNode orElse()?}) DocumentNode
The last element that satisfies the given predicate test.
inherited
map<T>(T toElement(DocumentNode e)) Iterable<T>
The current elements of this iterable modified by toElement.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reduce(DocumentNode combine(DocumentNode value, DocumentNode element)) DocumentNode
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
removeListener(DocumentChangeListener listener) → void
selectDownstreamPosition(DocumentPosition docPosition1, DocumentPosition docPosition2) DocumentPosition

Available on Document, provided by the InspectDocumentSelection extension

Given docPosition1 and docPosition2, returns the DocumentPosition that appears last in the document.
selectUpstreamPosition(DocumentPosition docPosition1, DocumentPosition docPosition2) DocumentPosition

Available on Document, provided by the InspectDocumentSelection extension

Given docPosition1 and docPosition2, returns the DocumentPosition that appears first in the document.
singleWhere(bool test(DocumentNode element), {DocumentNode orElse()?}) DocumentNode
The single element that satisfies test.
inherited
skip(int count) Iterable<DocumentNode>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(DocumentNode value)) Iterable<DocumentNode>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
take(int count) Iterable<DocumentNode>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(DocumentNode value)) Iterable<DocumentNode>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toHtml({DocumentSelection? selection, NodeHtmlSerializerChain nodeSerializers = defaultNodeHtmlSerializerChain, InlineHtmlSerializerChain inlineSerializers = defaultInlineHtmlSerializers, bool skipUnknownNodes = true}) String

Available on Document, provided by the HtmlSerialization extension

Converts this Document to an HTML representation.
toList({bool growable = true}) List<DocumentNode>
Creates a List containing the elements of this Iterable.
inherited
toPlainText({DocumentSelection? selection}) String

Available on Document, provided by the ToPlainText extension

Serializes this Document to a plain-text representation by writing the text from every TextNode to a String.
toSet() Set<DocumentNode>
Creates a Set containing the same elements as this iterable.
inherited
toString() String
A string representation of this object.
inherited
where(bool test(DocumentNode element)) Iterable<DocumentNode>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() Iterable<T>
Creates a new lazy Iterable with all elements that have type T.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited