direction property

  1. @override
TextDirection get direction
override

Implementation

@override
TextDirection get direction {
  // CSS 'direction' is inherited via the DOM parent chain. For out-of-flow
  // render reparenting (e.g., positioned elements), prefer the DOM parent’s
  // renderStyle over the render tree parent to ensure correct inheritance.
  if (_direction != null) return _direction!;
  final dom.Element? domParent = target.parentElement;
  if (domParent != null) {
    return domParent.renderStyle.direction;
  }
  // Fallback to render parent when DOM parent is unavailable (e.g., root).
  final RenderStyle? renderParent = parent;
  if (renderParent != null) return renderParent.direction;
  return TextDirection.ltr;
}
set direction (TextDirection? value)

Implementation

set direction(TextDirection? value) {
  if (_direction == value) return;
  _direction = value;
  // Update all the children text and flow layout with specified style property not set due to style inheritance.
  _markNestChildrenTextAndLayoutNeedsLayout(this, DIRECTION);

  // Overflow scroll containers build Flutter `Scrollable` widgets whose
  // `axisDirection` depends on the resolved text direction. When `direction`
  // changes on an ancestor (e.g. `dir="rtl"` on a root container), descendant
  // scrollable elements often inherit the new direction without setting their
  // own `direction` property, so their renderStyle updates but their Scrollable
  // wrappers won't rebuild automatically. Force a rebuild for any scrollable
  // elements in this subtree so horizontal overflow scrolling matches RTL/LTR.
  final dom.Element root = target;
  void requestScrollableRebuild(dom.Element el) {
    if (!el.hasScroll) return;
    el.renderStyle.requestWidgetToRebuild(UpdateDirectionReason());
  }

  requestScrollableRebuild(root);
  void visit(dom.Node node) {
    if (node is dom.Element) {
      requestScrollableRebuild(node);
      node.visitChildren(visit);
    }
  }
  root.visitChildren(visit);
}