getMenuX method

double getMenuX()

Get menu current offset

Implementation

double getMenuX() {
  if (widget.menu == null) {
    return 0;
  }

  double menuActualWidth = getActualMenuWidth();
  double fixedPanX = 0;

  if (widget.menuLocation == MenuLocation.left) {
    if (_isSubMenuOpen == false &&
        _panUpdateDetails != null &&
        _panStartDetails != null &&
        _panUpdateDetails!.globalPosition.dx < menuActualWidth) {
      double fixedPanStart = _panStartDetails!.globalPosition.dx;
      if (_panStartDetails!.globalPosition.dx > menuActualWidth) {
        fixedPanStart = menuActualWidth;
      }

      fixedPanX = _panUpdateDetails!.globalPosition.dx - fixedPanStart;
    }

    if (widget.menuCloseMode == MenuCloseMode.narrow) {
      // Menu offset is not changing if close mode is narrow (only width changes)
      return 0;
    } else if (_menuAnimation != null &&
        _menuAnimation!.value.isNaN == false) {
      double startX = -menuActualWidth;
      double endX = 0;
      return min<double>(
          0, (startX + (endX - startX) * _menuAnimation!.value) + fixedPanX);
    } else if (_isMenuOpen) {
      return 0;
    } else {
      return -menuActualWidth + fixedPanX;
    }
  } else {
    if (_isSubMenuOpen == false &&
        _panUpdateDetails != null &&
        _panStartDetails != null &&
        _panUpdateDetails!.globalPosition.dx >
            _availableSize.width - menuActualWidth) {
      // If pan starte inside menu
      double fixedPanStart = 0;
      if (_panStartDetails!.globalPosition.dx >
          _availableSize.width - menuActualWidth) {
        fixedPanStart = _panStartDetails!.globalPosition.dx -
            (_availableSize.width - menuActualWidth);
      }

      fixedPanX = _panUpdateDetails!.globalPosition.dx -
          (_availableSize.width - menuActualWidth) -
          fixedPanStart;
    }

    if (widget.menuCloseMode == MenuCloseMode.narrow) {
      // Menu offset is not changing if close mode is narrow (only width changes)
      return _availableSize.width - menuActualWidth;
    } else if (_menuAnimation != null &&
        _menuAnimation!.value.isNaN == false) {
      double startX = _availableSize.width;
      double endX = _availableSize.width - menuActualWidth;
      return max<double>(_availableSize.width - menuActualWidth,
          (startX + (endX - startX) * _menuAnimation!.value) + fixedPanX);
    } else if (_isMenuOpen) {
      return _availableSize.width - menuActualWidth;
    } else {
      return _availableSize.width + fixedPanX;
    }
  }
}