show static method

void show({
  1. required BuildContext context,
  2. required Widget child,
  3. double? top,
  4. double? left,
  5. double? bottom,
  6. double? right,
})

显示一个浮层。

context 用于获取当前 Overlaychild 为浮层内容; topleftbottomright 用于确定浮层位置。 重复调用时会先移除已经显示的浮层。

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!);
  }
}