toggleDropDown method

void toggleDropDown({
  1. bool close = false,
})

Implementation

void toggleDropDown({bool close = false}) {
  if (isMenuOpen()) {
    try {
      _overlayEntry?.remove();
      setState(() {
        _isMenuOpen.value = false;
      });
      widget.dropdownStatus != null ? widget.dropdownStatus!(false) : null;
    } catch (e) {
      print(e);
    }
  } else if (!close) {
    try {
      _overlayEntry = _createDropDownMenu();
      Overlay.of(context).insert(_overlayEntry!);
      widget.dropdownStatus != null ? widget.dropdownStatus!(true) : null;

      setState(() {
        _isMenuOpen.value = true;
      });
    } catch (e) {
      print(e);
    }
  }
}