Skip to main content

OverlayPortal

Struct OverlayPortal 

Source
pub struct OverlayPortal {
    pub key: Option<KeyRef>,
    pub controller: Ref<OverlayPortalController>,
    pub overlay_child_builder: WidgetBuilder,
    pub child: Option<WidgetRef>,
    pub overlay_location: OverlayChildLocation,
}
Expand description

A widget that renders its overlay child on an Overlay.

The overlay child is initially hidden until OverlayPortalController::show is called on the associated controller. The OverlayPortal uses overlay_child_builder to build its overlay child and renders it on the specified Overlay as if it was inserted using an OverlayEntry, while it can depend on the same set of InheritedWidgets that this widget can depend on.

This widget requires an Overlay ancestor in the widget tree when its overlay child is showing. The overlay child is rendered by the Overlay ancestor, not by the widget itself. This allows the overlay child to float above other widgets, independent of its position in the widget tree.

When OverlayPortalController::hide is called, the widget built using overlay_child_builder will be removed from the widget tree the next time the widget rebuilds. Stateful descendants in the overlay child subtree may lose state as a result.

§Paint Order

In an Overlay, an overlay child is painted after the OverlayEntry associated with its OverlayPortal (that is, the OverlayEntry closest to the OverlayPortal in the widget tree, which usually represents the enclosing Route), and before the next OverlayEntry.

When an OverlayEntry has multiple associated OverlayPortals, the paint order between their overlay children is the order in which OverlayPortalController::show was called. The last OverlayPortal to have called show gets to paint its overlay child in the foreground.

§Differences between OverlayPortal and OverlayEntry

The main difference between OverlayEntry and OverlayPortal is that OverlayEntry builds its widget subtree as a child of the target Overlay, while OverlayPortal uses overlay_child_builder to build a child widget of itself. This allows OverlayPortal’s overlay child to depend on the same set of InheritedWidgets as OverlayPortal, and it’s also guaranteed that the overlay child will not outlive its OverlayPortal.

On the other hand, OverlayPortal’s implementation is more complex. For instance, it does a bit more work than a regular widget during global key reparenting. If the content to be shown on the Overlay doesn’t benefit from being a part of OverlayPortal’s subtree, consider using an OverlayEntry instead.

See also:

  • OverlayEntry, an alternative API for inserting widgets into an Overlay.
  • Positioned, which can be used to size and position the overlay child in relation to the target Overlay’s boundaries.

Fields§

§key: Option<KeyRef>§controller: Ref<OverlayPortalController>

The controller to show, hide and bring to top the overlay child.

§overlay_child_builder: WidgetBuilder

A WidgetBuilder used to build a widget below this widget in the tree, that renders on the closest Overlay.

The said widget will only be built and shown in the closest Overlay once OverlayPortalController::show is called on the associated controller. It will be painted in front of the OverlayEntry closest to this widget in the widget tree (which is usually the enclosing Route).

The built overlay child widget is inserted below this widget in the widget tree, allowing it to depend on InheritedWidgets above it, and be notified when the InheritedWidgets change.

Unlike child, the built overlay child can visually extend outside the bounds of this widget without being clipped, and receive hit-test events outside of this widget’s bounds, as long as it does not extend outside of the Overlay on which it is rendered.

§child: Option<WidgetRef>

A widget below this widget in the tree.

§overlay_location: OverlayChildLocation

The Overlay that the widget returned from overlay_child_builder is attached to.

Implementations§

Source§

impl OverlayPortal

Source

pub fn new( controller: Ref<OverlayPortalController>, overlay_child_builder: impl Fn(&mut App, BuildContext) -> WidgetRef + 'static, ) -> OverlayPortal

Creates an OverlayPortal that renders the widget overlay_child_builder builds on the closest Overlay when OverlayPortalController::show is called.

The overlay_location sets which Overlay this widget attaches the widget returned by overlay_child_builder to. Defaults to OverlayChildLocation::NearestOverlay.

Source

pub fn targets_root_overlay( controller: Ref<OverlayPortalController>, overlay_child_builder: impl Fn(&mut App, BuildContext) -> WidgetRef + 'static, ) -> OverlayPortal

👎Deprecated:

Use OverlayPortal::new with an overlay_location of OverlayChildLocation::RootOverlay instead. This feature was deprecated after v3.33.0-0.0.pre.

Creates an OverlayPortal that renders the widget overlay_child_builder builds on the root Overlay when OverlayPortalController::show is called.

Deprecated in Flutter after v3.33.0-0.0.pre: use OverlayPortal::new with overlay_location set to OverlayChildLocation::RootOverlay instead.

Source

pub fn overlay_child_layout_builder( controller: Ref<OverlayPortalController>, overlay_child_builder: impl Fn(&mut App, BuildContext, OverlayChildLayoutInfo) -> WidgetRef + 'static, ) -> OverlayPortal

Creates an OverlayPortal that renders the widget overlay_child_builder builds on the closest Overlay when OverlayPortalController::show is called.

Developers can use overlay_child_builder to configure the overlay child based on the size and the location of child within the target Overlay, as well as the size of the Overlay itself. This allows the overlay child to, for example, always follow child and at the same time resize itself based on how close it is to the edges of the Overlay.

The overlay_child_builder callback is called during layout. To ensure the paint transform of child in relation to the target Overlay is up-to-date by then, all render objects between the OverlayPortal and the target Overlay must establish their paint transform during the layout phase, which most render objects do.

The overlay_location sets which Overlay this widget attaches the widget returned by overlay_child_builder to. Defaults to OverlayChildLocation::NearestOverlay.

Source

pub fn key(self, key: KeyRef) -> OverlayPortal

Dart OverlayPortal(key:).

Source

pub fn child<K>(self, child: impl IntoWidget<K>) -> OverlayPortal

Dart OverlayPortal(child:).

Source

pub fn overlay_location( self, overlay_location: OverlayChildLocation, ) -> OverlayPortal

Dart OverlayPortal(overlayLocation:).

Trait Implementations§

Source§

impl Debug for OverlayPortal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StatefulWidget for OverlayPortal

Source§

type State = OverlayPortalState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn create_state(&self) -> OverlayPortalState

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn debug_check_constructor(&self)

Source§

fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl !RefUnwindSafe for OverlayPortal

§

impl !Send for OverlayPortal

§

impl !Sync for OverlayPortal

§

impl !UnwindSafe for OverlayPortal

§

impl Forget for OverlayPortal

§

impl Freeze for OverlayPortal
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, NonZero<u32>: Freeze, PhantomData<fn() -> OverlayPortalController>: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement) -> Rc<dyn Widget>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement) -> Rc<dyn Widget>>>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze,

§

impl Move for OverlayPortal

§

impl Unpin for OverlayPortal
where Rc<dyn Key>: Unpin, NonZero<u32>: Unpin, Rc<Keep>: Unpin, Rc<dyn Fn(&mut App, AnyElement) -> Rc<dyn Widget>>: Unpin, Rc<dyn Widget>: Unpin,

§

impl UnsafeUnpin for OverlayPortal
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, PhantomData<fn() -> OverlayPortalController>: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyElement) -> Rc<dyn Widget>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement) -> Rc<dyn Widget>>>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>