show static method
void
show({})
显示一个浮层。
context 用于获取当前 Overlay,child 为浮层内容;
top、left、bottom 和 right 用于确定浮层位置。
重复调用时会先移除已经显示的浮层。
Implementation
static void show({
required BuildContext context,
required Widget child,
double? top,
double? left,
double? bottom,
double? right,
}) {
// 如果已存在,先移除
_entry?.remove();
_entry = OverlayEntry(
builder: (_) => Positioned(
top: top,
left: left,
right: right,
bottom: bottom,
child: child,
),
);
if (context.mounted && _entry != null) {
Overlay.of(context).insert(_entry!);
}
}