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, Map<
int, Object> ? placeholders]) -
Constructs an AttributedText whose content is comprised by a combination
of
textandplaceholders, covered by the given attributedspans.
Properties
- first → Object
-
Returns the character or placeholder at offset zero.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- hasListeners → bool
-
no setter
- isEmpty → bool
-
Returns
trueif the length of this AttributedText is zero.no setter - isNotEmpty → bool
-
Returns
trueif the length of this AttributedText is greater than zero.no setter - last → Object
-
Returns the character or placeholder at the end of this
AttributedText.no setter - length → int
-
Returns the
lengthof this AttributedText, which includes the length of the plain textString, and the number of placeholders.no setter -
placeholders
↔ Map<
int, Object> -
Placeholders that represent non-text content, e.g., inline images, that
should appear in the rendered text.
latefinal
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- spans → AttributedSpans
-
The attributes applied across the plain text and placeholders.
final
- text → String
-
The text that this AttributedText attributes.
no setter
Methods
-
addAttribution(
Attribution attribution, SpanRange range, {bool autoMerge = true, bool overwriteConflictingSpans = false}) → void -
Adds the given
attributionto all characters within the givenrange, 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.
-
computeInlineSpan(
BuildContext context, AttributionStyleBuilder styleBuilder, InlineWidgetBuilderChain inlineWidgetBuilders) → InlineSpan -
Available on AttributedText, provided by the ComputeTextSpan extension
Returns a Flutter InlineSpan comprised of styled text and widgets based on an AttributedText. -
computeTextSpan(
AttributionStyleBuilder styleBuilder) → TextSpan -
Available on AttributedText, provided by the ComputeTextSpan extension
Returns a Flutter TextSpan that is styled based on the attributions within this AttributedText. -
copy(
) → AttributedText - Returns a copy of this AttributedText.
-
copyAndAppend(
AttributedText other) → AttributedText -
Returns a copy of this AttributedText with the
othertext and attributions appended to the end. -
copyText(
int startOffset, [int? endOffset]) → AttributedText -
Copies all text, attributions, and placeholders from
startOffsettoendOffset, exclusive, and returns them as a new AttributedText. -
copyTextInRange(
SpanRange range) → AttributedText -
Copies all text and attributions from
range.starttorange.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 givenattributions. -
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 byattributionFilter. -
hasAttributionAt(
int offset, {Attribution? attribution}) → bool -
Returns true if the given
attributionis applied atoffset. -
hasAttributionsThroughout(
{required Set< Attribution> attributions, required SpanRange range}) → bool -
Returns true if this AttributedText contains each of the
given
attributionsthroughout the givenrange(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
attributionswithin the givenrange(inclusive). -
insert(
{required AttributedText textToInsert, required int startOffset}) → AttributedText -
Returns a copy of this AttributedText with
textToInsertinserted atstartOffset, retaining whatever attributions are already applied totextToInsert. -
insertPlaceholder(
int index, Object placeholder) → AttributedText -
insertPlaceholders(
Map< int, Object> placeholders) → AttributedText -
insertString(
{required String textToInsert, required int startOffset, Set< Attribution> applyAttributions = const {}}) → AttributedText -
Returns a copy of this AttributedText with
textToInsertinserted atstartOffset. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeAttribution(
Attribution attribution, SpanRange range) → void -
Removes the given
attributionfrom all characters within the givenrange, 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, toendOffset, exclusive. -
replaceAttributions(
AttributedSpans newSpans) → AttributedText -
Returns a copy of this AttributedText, replacing the existing
AttributedSpans with the given
newSpans. -
split(
String pattern) → List< AttributedText> -
Available on AttributedText, provided by the Split extension
-
substring(
int start, [int? end]) → String -
Returns a plain-text substring, from
starttoend(exclusive), or the end of this AttributedText ifendisn't provided. -
substringInRange(
SpanRange range) → String -
Returns a plain-text substring, from
range.starttorange.end(exclusive). -
toggleAttribution(
Attribution attribution, SpanRange range) → void -
If ALL of the text in
range, inclusive, contains the givenattribution, thatattributionis removed from the text inrange, inclusive. Otherwise, all of the text inrange, inclusive, is given theattribution. -
toHtml(
{int? start, int? end, InlineHtmlSerializerChain serializers = defaultInlineHtmlSerializers}) → String -
Available on AttributedText, provided by the AttributedTextToHtml extension
-
toMarkdown(
) → String -
Available on AttributedText, provided by the Markdown extension
-
toPlainText(
{bool includePlaceholders = true, String replacementCharacter = placeholderCharacter}) → String -
Returns a plain-text version of this
AttributedText. -
toString(
) → String -
A string representation of this object.
override
-
visitAttributions(
AttributionVisitor visitor) → void -
Visits all attributions in this AttributedText by calling
visitorwhenever 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
-
operator [](
int offset) → Object -
Returns the character or placeholder at the given
offset.
Constants
- placeholderCharacter → const String
- The default character that's inserted in place of placeholders when converting an AttributedText to plain text.