open method
打开悬浮窗 此方法配合 close方法进行使用,调用close之后在调用此方法会丢失 Floating 状态 否则请使用 hideFloating 进行隐藏,使用 showFloating进行显示,而不是使用 close
Implementation
open(BuildContext context) {
if (_isShowing) return;
// 先清理旧的 OverlayEntry
if (_overlayEntry != null) {
try {
_overlayEntry!.remove();
_overlayEntry!.dispose();
} catch (e) {
_log.log("清理旧 OverlayEntry 失败: $e");
}
_overlayEntry = null;
}
_overlayEntry = OverlayEntry(
builder: (context) {
return _floatingView;
},
);
Overlay.of(context).insert(_overlayEntry!);
_isShowing = true;
_notifyOpen();
}