getMenuOpenPercent method

double getMenuOpenPercent()

Get how many percents menu is moved (or resized) from close to the open state

Implementation

double getMenuOpenPercent() {
  double menuStartToEndDistance;
  double menuStartToCurrentDistance;

  // Default when menu is on left
  if (widget.menuCloseMode == MenuCloseMode.basic &&
      widget.menuLocation == MenuLocation.left) {
    double menuStart = -getActualMenuWidth();
    double menuEnd = 0;
    double menuCurrentX = getMenuX();
    menuStartToEndDistance = (menuEnd - menuStart).abs();
    menuStartToCurrentDistance = (menuStart - menuCurrentX).abs();
    // Default when menu is on right
  } else if (widget.menuCloseMode == MenuCloseMode.basic &&
      widget.menuLocation == MenuLocation.right) {
    double menuStart = _availableSize.width;
    double menuEnd = _availableSize.width - getActualMenuWidth();
    double menuCurrentX = getMenuX();
    menuStartToEndDistance = (menuEnd - menuStart).abs();
    menuStartToCurrentDistance = (menuStart - menuCurrentX).abs();
  }
  // Narrow
  else {
    double menuStartWidth = widget.menuNarrowWidth;
    double menuEndWidth = getMenuMaxWidth();
    double menuCurrentWidth = getActualMenuWidth();
    menuStartToEndDistance = (menuEndWidth - menuStartWidth).abs();
    menuStartToCurrentDistance = (menuStartWidth - menuCurrentWidth).abs();
  }

  if (menuStartToEndDistance == 0) {
    return 0;
  } else {
    return menuStartToCurrentDistance / menuStartToEndDistance;
  }
}