OverlayEntry class Null safety

A place in an Overlay that can contain a widget.

Overlay entries are inserted into an Overlay using the OverlayState.insert or OverlayState.insertAll functions. To find the closest enclosing overlay for a given BuildContext, use the Overlay.of function.

An overlay entry can be in at most one overlay at a time. To remove an entry from its overlay, call the remove function on the overlay entry.

Because an Overlay uses a Stack layout, overlay entries can use Positioned and AnimatedPositioned to position themselves within the overlay.

For example, Draggable uses an OverlayEntry to show the drag avatar that follows the user's finger across the screen after the drag begins. Using the overlay to display the drag avatar lets the avatar float over the other widgets in the app. As the user's finger moves, draggable calls markNeedsBuild on the overlay entry to cause it to rebuild. In its build, the entry includes a Positioned with its top and left property set to position the drag avatar near the user's finger. When the drag is over, Draggable removes the entry from the overlay to remove the drag avatar from view.

By default, if there is an entirely opaque entry over this one, then this one will not be included in the widget tree (in particular, stateful widgets within the overlay entry will not be instantiated). To ensure that your overlay entry is still built even if it is not visible, set maintainState to true. This is more expensive, so should be done with care. In particular, if widgets in an overlay entry with maintainState set to true repeatedly call State.setState, the user's battery will be drained unnecessarily.

OverlayEntry is a Listenable that notifies when the widget built by builder is mounted or unmounted, whose exact state can be queried by mounted. After the owner of the OverlayEntry calls remove and then dispose, the widget may not be immediately removed from the widget tree. As a result listeners of the OverlayEntry can get notified for one last time after the dispose call, when the widget is eventually unmounted.

See also:

Implemented types

Constructors

OverlayEntry({required WidgetBuilder builder, bool opaque = false, bool maintainState = false})
Creates an overlay entry.

Properties

builder WidgetBuilder
This entry will include the widget built by this builder in the overlay at the entry's position.
final
hashCode int
The hash code for this object.
read-onlyinherited
maintainState bool
Whether this entry must be included in the tree even if there is a fully opaque entry above it.
read / write
mounted bool
Whether the OverlayEntry is currently mounted in the widget tree.
read-only
opaque bool
Whether this entry occludes the entire overlay.
read / write
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object notifies its listeners.
override
dispose() → void
Discards any resources used by this OverlayEntry.
markNeedsBuild() → void
Cause this entry to rebuild during the next pipeline flush.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
remove() → void
Remove this entry from the overlay.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that the object notifies.
override
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited