编辑:看起来这在Flutter的最新版本中中断了。不知道为什么,但是我想Flutter现在会在确定完全不可见叠加层时避免绘制。该方法仍然可以使用,但是需要与翻译结合才能将其移出屏幕:https
:
//gist.github.com/itsJoKr/ce5ec57bd6dedf74d1737c1f39481913
有人建议使用
OverlayEntry,它看起来是最好的解决方案。
您可以将其
OverlayEntry放置在当前屏幕下方,以使该屏幕不可见并随
maintainState:true其构建。一个很大的优点是,由于它不与当前的窗口小部件树混合使用,因此易于实现。
OverlayState overlayState = Overlay.of(context);OverlayEntry entry = OverlayEntry(builder: (context) { return RepaintBoundary(key: key, child: yourWidget,); // Using RepaintBoundary to get RenderObject and convert to image}, maintainState: true);overlayState.insert(entry);// doesn't work anymore// overlayState.rearrange([entry], above: entry); // Didn't find how to insert it at the bottom of current overlays, so this should rearrange it so that our entry is at the bottom


