modalRouteContentRect function

Rect? modalRouteContentRect(
  1. ModalRoute route
)

The global bounds of what a modal route paints (its sheet, popup or dialog, not its barrier), for position-aware hiding and halo containment of the CN widgets under it (#149). Rect.zero when it paints nothing, null when that can't be told.

The route's render tree is walked from the root of its page, through render objects known to paint only their children (padding, alignment, clips, transforms, semantics, flex and stack layouts...), down to the first ones that may paint themselves: the sheet's Material, a DecoratedBox, a text, and so on. Their bounds make up the result. A render object of any other kind counts as painting its whole box, so an unknown tree errs on the side of covering more.

Implementation

Rect? modalRouteContentRect(ModalRoute<dynamic> route) {
  final root = route.subtreeContext?.findRenderObject();
  if (root is! RenderBox || !root.attached || !root.hasSize) return null;
  final walk = _ContentWalk();
  final rect = walk.bounds(root);
  if (walk.unknown) return null;
  return rect ?? Rect.zero;
}