Bidi class

This provides utility methods for working with bidirectional text. All of the methods are static, and are organized into a class primarily to group them together for documentation and discoverability.

Constructors

Bidi()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

detectRtlDirectionality(String str, {bool isHtml = false}) bool
Check the estimated directionality of str, return true if the piece of text should be laid out in RTL direction. If isHtml is true, the string is HTML or HTML-escaped.
endsWithLtr(String text, [dynamic isHtml = false]) bool
Determines if the exit directionality (ie, the last strongly-directional character in text is LTR. If isHtml is true, the text is HTML or HTML-escaped.
endsWithRtl(String text, [dynamic isHtml = false]) bool
Determines if the exit directionality (ie, the last strongly-directional character in text is RTL. If isHtml is true, the text is HTML or HTML-escaped.
enforceLtrInHtml(String html) String
Enforce the html snippet in LTR directionality regardless of overall context. If the html piece was enclosed by a tag, the direction will be applied to existing tag, otherwise a span tag will be added as wrapper. For this reason, if html snippet start with with tag, this tag must enclose the whole piece. If the tag already has a direction specified, this new one will override existing one in behavior (tested on FF and IE).
enforceLtrInText(String text) String
Enforce LTR on both end of the given text using unicode BiDi formatting characters LRE and PDF.
enforceRtlInHtml(String html) String
Enforce the html snippet in RTL directionality regardless of overall context. If the html piece was enclosed by a tag, the direction will be applied to existing tag, otherwise a span tag will be added as wrapper. For this reason, if html snippet start with with tag, this tag must enclose the whole piece. If the tag already has a direction specified, this new one will override existing one in behavior (should work on Chrome, FF, and IE since this was ported directly from the Closure version).
enforceRtlInText(String text) String
Enforce RTL on both end of the given text using unicode BiDi formatting characters RLE and PDF.
estimateDirectionOfText(String text, {bool isHtml = false}) TextDirection
Estimates the directionality of text using the best known general-purpose method (using relative word counts). A TextDirection.UNKNOWN return value indicates completely neutral input. isHtml is true if text HTML or HTML-escaped.
guardBracketInHtml(String str, [bool? isRtlContext]) String
Apply bracket guard to str using html span tag. This is to address the problem of messy bracket display that frequently happens in RTL layout. If isRtlContext is true, then we explicitly want to wrap in a span of RTL directionality, regardless of the estimated directionality.
guardBracketInText(String str, [bool? isRtlContext]) String
Apply bracket guard to str using LRM and RLM. This is to address the problem of messy bracket display that frequently happens in RTL layout. This version works for both plain text and html, but in some cases is not as good as guardBracketInHtml. If isRtlContext is true, then we explicitly want to wrap in a span of RTL directionality, regardless of the estimated directionality.
hasAnyLtr(String text, [dynamic isHtml = false]) bool
Determines if the given text has any LTR characters in it. If isHtml is true, the text is HTML or HTML-escaped.
hasAnyRtl(String text, [dynamic isHtml = false]) bool
Determines if the given text has any RTL characters in it. If isHtml is true, the text is HTML or HTML-escaped.
isRtlLanguage([String? languageString]) bool
Check if a BCP 47 / III languageString indicates an RTL language.
normalizeHebrewQuote(String str) String
Replace the double and single quote directly after a Hebrew character in str with GERESH and GERSHAYIM. This is most likely the user's intention.
startsWithLtr(String text, [dynamic isHtml = false]) bool
Determines if the first character in text with strong directionality is LTR. If isHtml is true, the text is HTML or HTML-escaped.
startsWithRtl(String text, [dynamic isHtml = false]) bool
Determines if the first character in text with strong directionality is RTL. If isHtml is true, the text is HTML or HTML-escaped.
stripHtmlIfNeeded(String text) String
Returns the input text with spaces instead of HTML tags or HTML escapes, which is helpful for text directionality estimation. Note: This function should not be used in other contexts. It does not deal well with many things: comments, script, elements, style elements, dir attribute,> in quoted attribute values, etc. But it does handle well enough the most common use cases. Since the worst that can happen as a result of these shortcomings is that the wrong directionality will be estimated, we have not invested in improving this.

Constants

LRE → const String
Unicode "Left-To-Right Embedding" (LRE) character.
LRM → const String
Unicode "Left-To-Right Mark" (LRM) character.
PDF → const String
Unicode "Pop Directional Formatting" (PDF) character.
RLE → const String
Unicode "Right-To-Left Embedding" (RLE) character.
RLM → const String
Unicode "Right-To-Left Mark" (RLM) character.