wrapWithUnicode method
- String text, {
- bool isHtml = false,
- bool resetDir = true,
- TextDirection? direction,
Format text
of a known (if specified) or estimated direction
for use
in plain-text output of the context directionality, so an
opposite-directionality text is neither garbled nor garbles what follows
it. Unlike wrapWithSpan, this makes use of unicode BiDi formatting
characters instead of spans for wrapping. The returned string would be
RLE+text+PDF for RTL text, or LRE+text+PDF for LTR text.
If resetDir
is true, and if the overall directionality or the exit
directionality of text are opposite to the context directionality,
a trailing unicode BiDi mark matching the context directionality is
appended (LRM or RLM).
In HTML, the only valid use of this function is inside of elements that
do not allow markup, e.g. an 'option' tag.
This function does not do HTML-escaping regardless of the value of
isHtml
. isHtml
is used to designate if the text contains HTML (escaped
or unescaped).
Implementation
String wrapWithUnicode(String text,
{bool isHtml = false, bool resetDir = true, TextDirection? direction}) {
direction ??= estimateDirection(text, isHtml: isHtml);
var result = text;
if (contextDirection.isDirectionChange(direction)) {
var marker = direction == TextDirection.RTL ? Bidi.RLE : Bidi.LRE;
result = '$marker$text${Bidi.PDF}';
}
return result + (resetDir ? _resetDir(text, direction, isHtml) : '');
}