custom_widgets/bidi_rich_text library
Workaround for https://github.com/flutter/flutter/issues/54400.
Flutter's paragraph engine fills the inline-placeholder slots of a line in logical order from left to right, even when the line reads right to left. The surrounding text runs are reordered correctly, so a paragraph such as
واحد \(two^2\) ثلاثة أربعة five ستة سبعة \(eight^8\)
renders every word in the right place but swaps the two formulas: the first one is pushed to the far left, where the last one belongs.
BidiText and BidiRichText undo that. Before the real layout they run a probe layout, work out the correct visual order of the placeholders on every line with the Unicode bidi reordering rule (UAX #9, rule L2), and then feed the placeholder sizes to the engine in the order the engine will consume them. The children are matched back up with the boxes afterwards.
When the computed order turns out to be the identity — no RTL involved, a single placeholder per line, an all-LTR line — nothing is changed and the behaviour is identical to a plain RichText.
Classes
- BidiRichText
- A RichText that lays inline widgets out in the correct visual order in bidirectional paragraphs.
- BidiText
-
A drop-in stand-in for
Text.richthat renders inline widgets in the right visual order in bidirectional paragraphs. - RenderBidiParagraph
- The render object behind BidiRichText.
Functions
-
needsBidiPlaceholderFix(
InlineSpan span) → bool -
Whether
spancan be hit by the placeholder-ordering bug.