Deprecate OverlayPortal.targetsRootOverlay and enforce LookupBoundary in Overlay.of
Learn about changes to the OverlayPortal and Overlay in Flutter.
Summary
#
The OverlayPortal.targetsRootOverlay property was deprecated and
replaced with overlayLocation.
The Overlay.of and Overlay.maybeOf now respect LookupBoundary.
Context
#
A overlayLocation parameter was added to
the OverlayPortal default constructor to
control where the overlay child renders.
As a result, the OverlayPortal.targetsRootOverlay constructor is
no longer useful.
To prevent an OverlayEntry from being inserted across multi-view boundaries
by mistake, Overlay.of now respects LookupBoundary.
Description of change
#The OverlayPortal.targetsRootOverlay constructor is deprecated.
The Overlay.of and Overlay.maybeOf will not lookup past LookupBoundary.
Migration guide
#
If you are using OverlayPortal.targetsRootOverlay,
use OverlayPortal with overlayLocation instead.
Case 1: trivial case
#Code before migration:
Widget build(BuildContext context) {
return OverlayPortal.targetsRootOverlay(
controller: myController,
overlayChildBuilder: _myBuilder,
child: myChild,
);
}
Code after migration:
Widget build(BuildContext context) {
return OverlayPortal(
overlayLocation: OverlayChildLocation.rootOverlay,
controller: myController,
overlayChildBuilder: _myBuilder,
child: myChild,
);
}
If you expect Overlay.of and Overlay.maybeOf to lookup past LookupBoundary,
use findAncestorStateOfType instead.
Code before migration:
Widget build(BuildContext context) {
Overlay.of(context);
// ...
}
Code after migration:
Widget build(BuildContext context) {
context.findAncestorStateOfType<OverlayState>();
// ...
}
Timeline
#
Landed in version: 3.38.0-0.1.pre
In stable release: 3.38
References
#API documentation:
Relevant issue:
Relevant PR:
Unless stated otherwise, the documentation on this site reflects Flutter 3.38.6. Page last updated on 2026-1-14. View source or report an issue.