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 anOverlay.Positioned, which can be used to size and position the overlay child in relation to the targetOverlay’s boundaries.
Fields§
§key: Option<KeyRef>See Widget::key.
controller: Ref<OverlayPortalController>The controller to show, hide and bring to top the overlay child.
overlay_child_builder: WidgetBuilderA 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: OverlayChildLocationThe Overlay that the widget returned from
overlay_child_builder is attached to.
Implementations§
Source§impl OverlayPortal
impl OverlayPortal
Sourcepub fn new(
controller: Ref<OverlayPortalController>,
overlay_child_builder: impl Fn(&mut App, BuildContext) -> WidgetRef + 'static,
) -> OverlayPortal
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.
Sourcepub 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.
pub fn targets_root_overlay( controller: Ref<OverlayPortalController>, overlay_child_builder: impl Fn(&mut App, BuildContext) -> WidgetRef + 'static, ) -> OverlayPortal
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.
Sourcepub fn overlay_child_layout_builder(
controller: Ref<OverlayPortalController>,
overlay_child_builder: impl Fn(&mut App, BuildContext, OverlayChildLayoutInfo) -> WidgetRef + 'static,
) -> OverlayPortal
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.
Sourcepub fn key(self, key: KeyRef) -> OverlayPortal
pub fn key(self, key: KeyRef) -> OverlayPortal
Dart OverlayPortal(key:).
Sourcepub fn child<K>(self, child: impl IntoWidget<K>) -> OverlayPortal
pub fn child<K>(self, child: impl IntoWidget<K>) -> OverlayPortal
Dart OverlayPortal(child:).
Sourcepub fn overlay_location(
self,
overlay_location: OverlayChildLocation,
) -> OverlayPortal
pub fn overlay_location( self, overlay_location: OverlayChildLocation, ) -> OverlayPortal
Dart OverlayPortal(overlayLocation:).
Trait Implementations§
Source§impl Debug for OverlayPortal
impl Debug for OverlayPortal
Source§impl StatefulWidget for OverlayPortal
impl StatefulWidget for OverlayPortal
Source§type State = OverlayPortalState
type State = OverlayPortalState
Source§fn create_state(&self) -> OverlayPortalState
fn create_state(&self) -> OverlayPortalState
Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
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 as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
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 OverlayPortalwhere
*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
impl UnsafeUnpin for OverlayPortalwhere
*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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.