AttributedText class

Text with attributions applied to desired spans of text.

An attribution can be any subclass of Attribution.

AttributedText is a convenient way to store and manipulate text that might have overlapping styles and/or non-style attributions. A common Flutter alternative is TextSpan, but TextSpan does not support overlapping styles, and TextSpan is exclusively intended for visual text styles.

Available extensions

Constructors

AttributedText([String? text, AttributedSpans? spans])

Properties

hashCode int
The hash code for this object.
no setteroverride
hasListeners bool
no setter
length int
Returns the length of this AttributedText's text String.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
spans AttributedSpans
The attributes applied to text.
final
text String
The text that this AttributedText attributes.
final

Methods

addAttribution(Attribution attribution, SpanRange range, {bool autoMerge = true, bool overwriteConflictingSpans = false}) → void
Adds the given attribution to all characters within the given range, inclusive.
addListener(VoidCallback listener) → void
clearAttributions(SpanRange range) → void
Removes all attributions within the given range.
computeAttributionSpans() Iterable<MultiAttributionSpan>
Collapses all attribution markers down into a series of attribution groups, starting at the beginning of this AttributedText, until the end.
copy() AttributedText
Returns a copy of this AttributedText.
copyAndAppend(AttributedText other) AttributedText
Returns a copy of this AttributedText with the other text and attributions appended to the end.
copyText(int startOffset, [int? endOffset]) AttributedText
Copies all text and attributions from startOffset to endOffset, exclusive, and returns them as a new AttributedText.
copyTextInRange(SpanRange range) AttributedText
Copies all text and attributions from range.start to range.end (exclusive), and returns them as a new AttributedText.
dispose() → void
getAllAttributionsAt(int offset) Set<Attribution>
Returns all attributions applied to the given offset.
getAllAttributionsThroughout(SpanRange range) Set<Attribution>
Returns all attributions that appear throughout the entirety of the given range.
getAttributedRange(Set<Attribution> attributions, int offset) SpanRange
Returns the range about offset, which is attributed with all given attributions.
getAttributionSpans(Set<Attribution> attributions) Set<AttributionSpan>
Returns all spans in this AttributedText for the given attributions.
getAttributionSpansByFilter(AttributionFilter filter) Set<AttributionSpan>
Returns all spans in this AttributedText, for attributions that are selected by the given filter.
getAttributionSpansInRange({required AttributionFilter attributionFilter, required SpanRange range, bool resizeSpansToFitInRange = false}) Set<AttributionSpan>
Returns spans for each attribution that (at least partially) appear within the given range, as selected by attributionFilter.
hasAttributionAt(int offset, {Attribution? attribution}) bool
Returns true if the given attribution is applied at offset.
hasAttributionsThroughout({required Set<Attribution> attributions, required SpanRange range}) bool
Returns true if this AttributedText contains each of the given attributions throughout the given range (inclusive).
hasAttributionsWithin({required Set<Attribution> attributions, required SpanRange range}) bool
Returns true if this AttributedText contains at least one character with each of the given attributions within the given range (inclusive).
insert({required AttributedText textToInsert, required int startOffset}) AttributedText
Returns a copy of this AttributedText with textToInsert inserted at startOffset, retaining whatever attributions are already applied to textToInsert.
insertString({required String textToInsert, required int startOffset, Set<Attribution> applyAttributions = const {}}) AttributedText
Returns a copy of this AttributedText with textToInsert inserted at startOffset.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeAttribution(Attribution attribution, SpanRange range) → void
Removes the given attribution from all characters within the given range, inclusive.
removeListener(VoidCallback listener) → void
removeRegion({required int startOffset, required int endOffset}) AttributedText
Copies this AttributedText and removes a region of text and attributions from startOffset, inclusive, to endOffset, exclusive.
substring(int start, [int? end]) String
Returns a plain-text substring of text, from start to end (exclusive), or the end of text if end isn't provided.
substringInRange(SpanRange range) String
Returns a plain-text substring of text, from range.start to range.end (exclusive).
toggleAttribution(Attribution attribution, SpanRange range) → void
If ALL of the text in range, inclusive, contains the given attribution, that attribution is removed from the text in range, inclusive. Otherwise, all of the text in range, inclusive, is given the attribution.
toString() String
A string representation of this object.
override
visitAttributions(AttributionVisitor visitor) → void
Visits all attributions in this AttributedText by calling visitor whenever an attribution begins or ends.
visitAttributionSpans(AttributionSpanVisitor visitor) → void
Visits attributions in this AttributedText, reporting every changing group of attributions to the given visitor.

Operators

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