Fixed that previous value, not current value has been taken to fetch suggestions

This commit is contained in:
dankito 2024-09-09 02:32:22 +02:00
parent 414295adbc
commit 335c5923d6
1 changed files with 4 additions and 4 deletions

View File

@ -43,13 +43,13 @@ fun <T> AutocompleteTextField(
val coroutineScope = rememberCoroutineScope()
fun fetchSuggestionsAsync() {
fun fetchSuggestionsAsync(query: String) {
suggestionsFetchJob?.cancel()
suggestionsFetchJob = coroutineScope.launch {
isLoading = true
suggestions = fetchSuggestions(value)
suggestions = fetchSuggestions(query)
isLoading = false
if (expanded == false && suggestions.isNotEmpty()) {
@ -67,7 +67,7 @@ fun <T> AutocompleteTextField(
onEnteredTextChanged(query)
if (query.length >= minTextLengthForSearch) {
fetchSuggestionsAsync()
fetchSuggestionsAsync(query)
} else {
suggestions = emptyList()
expanded = false
@ -75,7 +75,7 @@ fun <T> AutocompleteTextField(
},
modifier = Modifier.fillMaxWidth().focusRequester(textFieldFocus).onFocusChanged { focusState ->
if (focusState.isFocused && minTextLengthForSearch == 0) {
fetchSuggestionsAsync()
fetchSuggestionsAsync(value)
}
},
label = { Text(label) },