showOverlayWindow static method
OverlayController?
showOverlayWindow(
- BuildContext context,
- GlobalKey<
State< ? targetKey, {StatefulWidget> > - Widget? content,
- OverlayPopDirection popDirection = OverlayPopDirection.bottom,
- bool autoDismissOnTouchOutSide = true,
- Function? onDismiss,
OverlayWindow 工具方发,用于快速弹出 Overlay,
返回 OverlayController 用于控制 Overlaywindow 的隐藏
targetKey
锚点 Widget 的 key,用于 OverlayWindow 的定位
popDirection
OverlayWindow 相对于 key 的展示位置, 默认 bottom
content
要展示的内容
autoDismissOnTouchOutSide
点击 OverlayWindow 外部是否自动消失,默认为 true
onDismiss
OverlayWindow 消失回调
Implementation
static OverlayController? showOverlayWindow(
BuildContext context, GlobalKey? targetKey,
{Widget? content,
OverlayPopDirection popDirection = OverlayPopDirection.bottom,
bool autoDismissOnTouchOutSide = true,
Function? onDismiss}) {
assert(content != null);
assert(targetKey != null);
assert(content != null);
if (content == null || targetKey == null) return null;
OverlayController? overlayController;
OverlayEntry entry = OverlayEntry(builder: (context) {
return GestureDetector(
behavior: (autoDismissOnTouchOutSide)
? HitTestBehavior.opaque
: HitTestBehavior.deferToChild,
onTap: (autoDismissOnTouchOutSide)
? () {
overlayController?.removeOverlay();
if (onDismiss != null) {
onDismiss();
}
}
: null,
child: OverlayWindow(
context: context,
content: content,
targetKey: targetKey,
popDirection: popDirection,
));
});
overlayController = OverlayController._(context, entry)..showOverlay();
return overlayController;
}