Fixed that previous value, not current value has been taken to fetch suggestions
This commit is contained in:
parent
414295adbc
commit
335c5923d6
|
@ -43,13 +43,13 @@ fun <T> AutocompleteTextField(
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
|
|
||||||
fun fetchSuggestionsAsync() {
|
fun fetchSuggestionsAsync(query: String) {
|
||||||
suggestionsFetchJob?.cancel()
|
suggestionsFetchJob?.cancel()
|
||||||
|
|
||||||
suggestionsFetchJob = coroutineScope.launch {
|
suggestionsFetchJob = coroutineScope.launch {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
|
|
||||||
suggestions = fetchSuggestions(value)
|
suggestions = fetchSuggestions(query)
|
||||||
|
|
||||||
isLoading = false
|
isLoading = false
|
||||||
if (expanded == false && suggestions.isNotEmpty()) {
|
if (expanded == false && suggestions.isNotEmpty()) {
|
||||||
|
@ -67,7 +67,7 @@ fun <T> AutocompleteTextField(
|
||||||
onEnteredTextChanged(query)
|
onEnteredTextChanged(query)
|
||||||
|
|
||||||
if (query.length >= minTextLengthForSearch) {
|
if (query.length >= minTextLengthForSearch) {
|
||||||
fetchSuggestionsAsync()
|
fetchSuggestionsAsync(query)
|
||||||
} else {
|
} else {
|
||||||
suggestions = emptyList()
|
suggestions = emptyList()
|
||||||
expanded = false
|
expanded = false
|
||||||
|
@ -75,7 +75,7 @@ fun <T> AutocompleteTextField(
|
||||||
},
|
},
|
||||||
modifier = Modifier.fillMaxWidth().focusRequester(textFieldFocus).onFocusChanged { focusState ->
|
modifier = Modifier.fillMaxWidth().focusRequester(textFieldFocus).onFocusChanged { focusState ->
|
||||||
if (focusState.isFocused && minTextLengthForSearch == 0) {
|
if (focusState.isFocused && minTextLengthForSearch == 0) {
|
||||||
fetchSuggestionsAsync()
|
fetchSuggestionsAsync(value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
label = { Text(label) },
|
label = { Text(label) },
|
||||||
|
|
Loading…
Reference in New Issue