# Deprecate `OverlayPortal.targetsRootOverlay` and enforce `LookupBoundary` in `Overlay.of`

> Learn about changes to the OverlayPortal and Overlay in Flutter.




:::important
These breaking change docs are accurate, as of the release
under which they are published. Over time, the
workarounds described here might become inaccurate.
We don't, in general, keep these breaking change docs up
to date as of each release.

这些破坏性改动文档的准确性仅限于其发布时对应的版本。
随着时间的推移，文档中描述的方案可能会逐渐失效。
通常情况下，我们不会在每次发布新版本时都对这些文档进行同步更新。

The [breaking change index file](/release/breaking-changes)
lists the docs created for each release.

[破坏性改动列表](/release/breaking-changes) 
列出了每个版本的文档。

:::


## 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:

```dart
Widget build(BuildContext context) {
  return OverlayPortal.targetsRootOverlay(
    controller: myController,
    overlayChildBuilder: _myBuilder,
    child: myChild,
  );
}
```

Code after migration:

```dart highlightLines=3
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:

```dart
Widget build(BuildContext context) {
  Overlay.of(context);
  // ...
}
```

Code after migration:

```dart
Widget build(BuildContext context) {
  context.findAncestorStateOfType<OverlayState>();
  // ...
}
```

## Timeline

Landed in version: 3.38.0-0.1.pre<br>
In stable release: 3.38

## References

API documentation:

* [`OverlayPortal`][]
* [`Overlay.of`][]
* [`Overlay.maybeOf`][]
* [`LookupBoundary`][]

Relevant issue:

* [Issue 168785][]

Relevant PR:

* [PR 174239][]

[`OverlayPortal`]: https://api.flutter-io.cn/flutter/widgets/OverlayPortal-class.html
[`Overlay.of`]: https://api.flutter-io.cn/flutter/widgets/Overlay/of.html
[`Overlay.maybeOf`]: https://api.flutter-io.cn/flutter/widgets/Overlay/maybeOf.html
[`LookupBoundary`]: https://api.flutter-io.cn/flutter/widgets/LookupBoundary-class.html
[Issue 168785]: https://github.com/flutter/flutter/issues/168785
[PR 174239]: https://github.com/flutter/flutter/pull/174239

