Google is committed to advancing racial equity for Black communities. See how.

viewport property

*<Null safety>*

dynamic viewport

Returns the viewport rect of the child view in parent's coordinates.

This only works if there is one and only one widget that has the Key set to GlobalObjectKey using this constroller's instance. FuchsiaView set's its key to the controller instance passed to it.

Returns null if the child view has not been rendered.

Implementation

Rect? get viewport {
  final key = GlobalObjectKey(this);
  RenderBox? box = key.currentContext?.findRenderObject() as RenderBox?;
  if (box?.hasSize == true) {
    final offset = box!.localToGlobal(Offset.zero);
    return offset & box.size;
  }
  return null;
}