buildOverlay method

  1. @protected
  2. @mustCallSuper
  3. @override
Widget buildOverlay(
  1. BuildContext context
)
override

构建 overlay 内容小部件

Implementation

@protected
@mustCallSuper
@override
Widget buildOverlay(BuildContext context) {
  // 阻止 popup 的滚动事件向外部传递,因为 ElApp 注册了监听子类滚动,
  // 由于 popup 弹窗与子组件是分离的,所以没有必要让 popup 滚动事件冒泡到 ElApp 中
  final result = NotificationListener<ScrollNotification>(
    onNotification: (v) => true,
    child: Builder(
      builder: (context) {
        _layerOffset = Offset.zero;
        _calcPopupAlignment();
        _setPositionType();
        _calcLayerOffset();
        return CompositedTransformFollower(
          link: layerLink,
          offset: layerOffset,
          showWhenUnlinked: false,
          child: SizedBox.fromSize(
            size: popupSize,
            child: ElTapOutSide(
              groupId: groupId,
              onTapDown: (e) {
                if (removeBehavior == ElPopupRemoveBehavior.tapDown) {
                  modelValue = false;
                }
              },
              onTapUp: (e) {
                if (removeBehavior == ElPopupRemoveBehavior.tapUp) {
                  modelValue = false;
                }
              },
              onTap: () {
                if (removeBehavior == ElPopupRemoveBehavior.tap) {
                  modelValue = false;
                }
              },
              child: buildPopup(context),
            ),
          ),
        );
      },
    ),
  );

  final popupConstraints = this.popupConstraints;

  // 计算 Popup 尺寸,若 popupConstraints 满足 tight 条件,那么无需对 Popup 的尺寸进行探测
  if (popupConstraints.isTight) {
    _isTight = true;
    _popupSize = Size(popupConstraints.maxWidth, popupConstraints.maxHeight);
    return UnconstrainedBox(child: result);
  } else {
    _isTight = false;
    return ElChildSizeBuilder(
      constraints: popupConstraints,
      tempChild: widget.overlayBuilder(context),
      builder: (size) {
        _popupSize = size;
        return result;
      },
    );
  }
}