BlueskyText class sealed
This class provides high-performance analysis of Bluesky Social's text and features related to secure posting.
By using the analysis feature of this class, you can get the values of all the following entities contained in the text and the Indices that can be used as is when posting using the Bluesky API.
The value of this Indices is counted based on the number of byte characters
and can be used as is for ByteSlice in the facets parameter of
app.bsky.feed.post in the Bluesky API.
It supports analysis of the following entities.
- Handle (like @shinyakato.dev)
- Link (like https://shinyakato.dev)
- Tag (like #hashtag)
The class also supports counting the number of characters using grapheme,
and the length of the string that can be obtained with length is
the one counted using grapheme. In other words, as per Bluesky Social's
official specifications, an emoji is counted as one character.
How To Use
You simply pass any text to the BlueskyText object to create an instance like following.
final text = BlueskyText(
'I speak 日本語 and English 🚀 @shinyakato.dev and @shinyakato.bsky.social. '
'Visit 🚀 https://shinyakato.dev.',
);
The length of the string passed to BlueskyText can be longer than 300 characters in grapheme. But, if there is a possibility that more than 300 characters of text will be passed, be sure to check if the character count is exceeded and split the BlueskyText using the split method as follows.
final text = BlueskyText(
'I speak 日本語 and English 🚀 @shinyakato.dev and @shinyakato.bsky.social. '
'Visit 🚀 https://shinyakato.dev.',
);
if (text.isLengthLimitExceeded) {
final texts = text.split();
for (final text in texts) {
print(text.handles);
print(text.links);
print(text.entities);
}
} else {
print(text.handles);
print(text.links);
print(text.entities);
}
Constructors
- BlueskyText(String text, {bool enableMarkdown, LinkConfig? linkConfig, Replacements? replacements})
-
Returns the new instance of BlueskyText.
factory
Properties
-
Returns the collection of cashtags.
no setter
- entities → Entities
-
Returns the collection of entities.
no setter
- formatted → BlueskyText
-
The formatted, posting-ready form of this text — the same instance
format returns, memoized (markdown expanded, links shortened).
no setter
- handles → Entities
-
Returns the collection of handles.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmojiOnly → bool
-
Returns true if this text contains only emoji, otherwise false.
no setter
- isEmpty → bool
-
Returns true if this value is empty, otherwise false.
no setter
- isLengthLimitExceeded → bool
-
Returns true if this text exceeds either post limit — more than 300
graphemes (length) or more than 3000 UTF-8 bytes — otherwise false.
no setter
- isNotEmojiOnly → bool
-
Returns true if this text not contains only emoji, otherwise false.
no setter
- isNotEmpty → bool
-
Returns true if this value is not empty, otherwise false.
no setter
- isNotLengthLimitExceeded → bool
-
Returns true if this text is within both post limits — at most 300
graphemes (length) and at most 3000 UTF-8 bytes — otherwise false.
no setter
- length → int
-
Returns the length of this value.
no setter
- links → Entities
-
Returns the collection of links.
no setter
- overflow → TextLengthOverflow?
-
Returns the range of value that exceeds the post-length limit, or
nullwhen the text is within both limits (isNotLengthLimitExceeded).no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
segments
→ List<
TextSegment> -
Returns value partitioned into non-overlapping, gap-free TextSegments
in document order, each tagged with the entities it belongs to (if any)
and whether it lies in the overflow region.
no setter
-
Returns the collection of tags.
no setter
- value → String
-
Returns the resource text.
no setter
Methods
-
format(
) → BlueskyText - Returns a new formatted BlueskyText based on configs.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
split(
) → List< BlueskyText> - Splits this value.
-
toPostData(
{String? service, HandleResolver? resolver}) → Future< ({List< Map< facets, String text, List<String, dynamic> >String> unresolvedHandles})> - Builds everything needed to create a post in a single call: the formatted value, its facets, and any handles that failed to resolve.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited