getActualMenuWidth method
Get menu current width
Implementation
double getActualMenuWidth() {
if (widget.menu == null) {
return 0;
}
// If menu close mode is 'Narrow' then menu width changes based on menu animation
else if (widget.menuCloseMode == MenuCloseMode.narrow) {
double startWidth = widget.menuNarrowWidth;
double endWidth = 0;
if (widget.menuWidth.isFinite) {
endWidth = widget.menuWidth;
} else if (widget.menuSpacing != 0) {
endWidth = _availableSize.width - widget.menuSpacing;
} else {
endWidth = _availableSize.width;
}
double menuAnimationProcess = 0;
if (_menuAnimation != null) {
menuAnimationProcess = _menuAnimation!.value;
} else if (_isMenuOpen) {
menuAnimationProcess = 1;
}
// Change menu width to narrow if panned
double fixedPanX = 0;
if (_isSubMenuOpen == false &&
_panUpdateDetails != null &&
_panStartDetails != null) {
// Fix pan if pan is started from inside menu
double fixedPanStart = 0;
double globalX = _panUpdateDetails!.globalPosition.dx;
double startX = _panStartDetails!.globalPosition.dx;
if (widget.menuLocation == MenuLocation.left &&
globalX < widget.menuWidth) {
if (startX > widget.menuWidth) {
fixedPanStart = widget.menuWidth;
} else {
fixedPanStart = startX;
}
fixedPanX = globalX - fixedPanStart;
} else if (widget.menuLocation == MenuLocation.right &&
globalX > _availableSize.width - widget.menuWidth) {
double fixedPanStart = 0;
if (startX > _availableSize.width - widget.menuWidth) {
fixedPanStart = startX - (_availableSize.width - widget.menuWidth);
}
fixedPanX = globalX -
(_availableSize.width - widget.menuWidth) -
fixedPanStart;
fixedPanX = -fixedPanX;
}
}
double menuMaxWidth = widget.menuWidth.isInfinite
? _availableSize.width - widget.menuSpacing
: widget.menuWidth;
double width = startWidth +
(endWidth - startWidth) * menuAnimationProcess +
fixedPanX;
width = min<double>(menuMaxWidth, width);
width = max<double>(widget.menuNarrowWidth, width);
return width;
}
// If menu close mode is 'Default' then menu width is not changing
else {
if (widget.menuWidth.isFinite) {
return widget.menuWidth;
} else if (widget.menuSpacing != 0) {
return _availableSize.width - widget.menuSpacing;
} else {
return _availableSize.width;
}
}
}