needsBidiPlaceholderFix function
Whether span can be hit by the placeholder-ordering bug.
Two or more inline widgets are needed for an ordering to exist at all, and some right-to-left text is needed for the visual order to differ from the logical one. Anything else keeps using a stock Text.
Implementation
bool needsBidiPlaceholderFix(InlineSpan span) {
var placeholders = 0;
var hasRtl = false;
void visit(InlineSpan current) {
if (current is PlaceholderSpan) {
placeholders++;
}
if (current is TextSpan) {
final text = current.text;
if (!hasRtl && text != null && _rtlPattern.hasMatch(text)) {
hasRtl = true;
}
final children = current.children;
if (children != null) {
for (final child in children) {
visit(child);
}
}
}
}
visit(span);
return placeholders >= 2 && hasRtl;
}