Remove this entry from the overlay.
This should only be called once.
If this method is called while the SchedulerBinding.schedulerPhase is
SchedulerBinding.persistentCallbacks, i.e. during the build, layout, or
paint phases (see WidgetsBinding.beginFrame), then the removal is
delayed until the post-frame callbacks phase. Otherwise the removal is
done synchronously. This means that it is safe to call during builds, but
also that if you do call this during a build, the UI will not update until
the next frame (i.e. many milliseconds later).
Source
void remove() {
assert(_overlay != null);
OverlayState overlay = _overlay;
_overlay = null;
if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.persistentCallbacks) {
SchedulerBinding.instance.addPostFrameCallback((Duration duration) {
overlay._remove(this);
});
} else {
overlay._remove(this);
}
}