showAsDropDown<T> function

Future<T?> showAsDropDown<T>(
  1. BuildContext context, {
  2. required Widget popupWindow,
  3. Offset offset = Offset.zero,
  4. bool fullWidth = true,
})

Implementation

Future<T?> showAsDropDown<T>(BuildContext context, {
  required Widget popupWindow,
  Offset offset = Offset.zero,
  bool fullWidth = true,
}) {
  ///获取本控件的渲染对象
  final RenderBox button = context.findRenderObject() as RenderBox;

  ///获取本控件覆盖物的渲染对象
  final RenderBox overlay = Overlay.of(context)?.context.findRenderObject() as RenderBox;

  ///计算弹窗的弹出位置,widget.offset为偏移数据,默认在button底部弹出。
  final RelativeRect position = new RelativeRect.fromRect(
    new Rect.fromPoints(
      button.localToGlobal(button.size.bottomLeft(offset),
          ancestor: overlay),
      button.localToGlobal(button.size.bottomRight(offset),
          ancestor: overlay),
    ),
    Offset.zero & overlay.size,
  );

  return showPopupWindow(
    context: context,
    popupWindow: popupWindow,
    position: position,
    fullWidth: fullWidth,
  );
}