getYOffset method
Decides whether to show the suggestions on top or bottom of Searchfield User can have more control by manually specifying the offset
Implementation
Offset? getYOffset(
Offset textFieldOffset, Size textFieldSize, int suggestionsCount) {
if (mounted) {
final size = MediaQuery.of(context).size;
final isSpaceAvailable = size.height >
textFieldOffset.dy + textFieldSize.height + _totalHeight;
if (widget.suggestionDirection == SuggestionDirection.down) {
return Offset(0, textFieldSize.height);
} else if (widget.suggestionDirection == SuggestionDirection.up) {
// search results should not exceed maxSuggestionsInViewPort
if (suggestionsCount > widget.maxSuggestionsInViewPort) {
return Offset(
0, -(widget.itemHeight * widget.maxSuggestionsInViewPort));
} else {
return Offset(0, -(widget.itemHeight * suggestionsCount));
}
} else {
if (!_isDirectionCalculated) {
_isDirectionCalculated = true;
if (isSpaceAvailable) {
_offset = Offset(0, textFieldSize.height);
return _offset;
} else {
if (suggestionsCount > widget.maxSuggestionsInViewPort) {
_offset = Offset(
0, -(widget.itemHeight * widget.maxSuggestionsInViewPort));
return _offset;
} else {
_offset = Offset(0, -(widget.itemHeight * suggestionsCount));
return _offset;
}
}
} else {
return _offset;
}
}
}
return null;
}