Skip to content

Migrate usage of OverlayPortal with RenderBox.localToGlobal to OverlayPortal.overlayChildLayoutBuilder #173440

@victorsanni

Description

@victorsanni

Use case

RenderBox.localToGlobal uses getTransformTo which is called during the layout phase. Calling getTransformTo at build phase to build an overlay child causes a frame delay because changes are scheduled for the next build. This can lead to bugs like #167359 and #168545.

Proposal

The new OverlayPortal.overlayChildLayoutBuilder was added to solve this problem:

/// Creates an [OverlayPortal] that renders the widget `overlayChildBuilder`
/// builds on the closest [Overlay] when [OverlayPortalController.show] is
/// called.
///
/// Developers can use `overlayChildBuilder` to configure the overlay child
/// based on the the size and the location of [OverlayPortal.child] within the
/// target [Overlay], as well as the size of the [Overlay] itself. This allows
/// the overlay child to, for example, always follow [OverlayPortal.child] and
/// at the same time resize itself base on how close it is to the edges of
/// the [Overlay].
///
/// The `overlayChildBuilder` callback is called during layout. To ensure the
/// paint transform of [OverlayPortal.child] in relation to the target
/// [Overlay] is up-to-date by then, all [RenderObject]s between the
/// [OverlayPortal] to the target [Overlay] must establish their paint
/// transform during the layout phase, which most [RenderObject]s do. One
/// exception is the [CompositedTransformFollower] widget, whose [RenderObject]
/// only establishes the paint transform when composited. Putting a
/// [CompositedTransformFollower] between the [OverlayPortal] and the [Overlay]
/// may resulting in an incorrect child paint transform being provided to the
/// `overlayChildBuilder` and will cause an assertion in debug mode.
OverlayPortal.overlayChildLayoutBuilder({

Migrate usage of OverlayPortal with RenderBox.localToGlobal to OverlayPortal.overlayChildLayoutBuilder, for example, in RawMenuAnchor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions