setOffset method

void setOffset()

Implementation

void setOffset() {
  // inputBox info
  dynamic inputBox = widget.inputKey.currentContext!.findRenderObject();
  Offset inputPosition = inputBox!.localToGlobal(Offset.zero);

  double actualBoxHeight = widget.dropdownHeight +
      widget.dropdownPadding.top +
      widget.dropdownPadding.bottom;
  double inputCenterPosition =
      inputPosition.dy + (inputBox.size.height * 0.5);
  double sidePadding =
      widget.dropdownPadding.right + widget.dropdownPadding.left;
  isTop = (inputCenterPosition < widget.screenHeight * 0.5);

  if (isTop) {
    // position dropbox top
    dropdownOffset = setDropdownPosition(
        isTop: true,
        sidePadding: sidePadding,
        inputBox: inputBox,
        inputPosition: inputPosition,
        actualBoxHeight: actualBoxHeight);
    triangleOffset = setTrianglePosition(
        dropdownOffset: dropdownOffset, sidePadding: sidePadding);

    if (widget.screenHeight < actualBoxHeight + dropdownOffset.dy) {
      setState(() {
        widget.dropdownHeight = widget.screenHeight - dropdownOffset.dy - 10;
      });
    }
  } else {
    // position dropbox bottom
    dropdownOffset = setDropdownPosition(
        isTop: false,
        sidePadding: sidePadding,
        inputBox: inputBox,
        inputPosition: inputPosition,
        actualBoxHeight: actualBoxHeight);
    Offset bottomOffset = dropdownOffset +
        Offset(0, widget.dropdownHeight + widget.triangleHeight);
    triangleOffset = setTrianglePosition(
        dropdownOffset: bottomOffset, sidePadding: sidePadding);
    setState(() {
      // triangle upsideDown
      upsideDown = true;
      double extraHeight = widget.screenHeight -
          (widget.screenHeight - inputPosition.dy) -
          widget.gap -
          10;
      if (widget.dropdownHeight > extraHeight) {
        widget.dropdownHeight = extraHeight;
        dropdownOffset = Offset(dropdownOffset.dx, 10);
      }
    });
  }
}