None 如果可以使用提供的参数调用以下函数 Jetpack Compose 错误

None if the following functions can be called with the Arguments supplied Jetpack Compose Error

每当我尝试在 Compose 中使用文本字段时,我都会收到此错误,我已经尝试了两种文本字段实现,即带有字符串值和 TextFieldValue 参数的实现,但仍然收到错误,我也尝试过使用 var text = rememberSaveable{mutableStateOf("")}var text by remember {mutableStateOf("")}。我也尝试过提升状态,这是我最初想做的,但仍然出现错误

这是代码

fun SearchAppBar(
    query: String,
    onQueryChanged: (String) -> Unit,
    onExecuteSearch: () -> Unit,
    scrollPosition: Int,
    selectedCategory: FoodCategory?,
    onSelectedCategoryChanged: (String) -> Unit,
    onCategoryChangePosition: (Int) -> Unit,
) {

    Surface(
        modifier = Modifier.fillMaxWidth(),
        color = Color.White,
        elevation = 8.dp,
    ) {
        Column {
            Row(
                modifier = Modifier.fillMaxWidth(),
            ) {
                TextField(
                    modifier = Modifier
                        .fillMaxWidth(.9f)
                        .padding(8.dp),
                    value = query,
                    onValueChange = {
                        onQueryChanged(it)
                    },
                    label = {
                        Text(text = "Search")
                    },
                    keyboardOptions = KeyboardOptions(
                        keyboardType = KeyboardType.Text,
                        imeAction = ImeAction.Done,
                    ),
                    leadingIcon = {
                        Icon(Icons.Filled.Search)
                    },
                    onImeActionPerformed = { action, softKeyboardController ->
                        if (action == ImeAction.Done) {
                            onExecuteSearch()
                            softKeyboardController?.hideSoftwareKeyboard()
                        }
                    },
                    textStyle = TextStyle(color = MaterialTheme.colors.onSurface),
                    backgroundColor = MaterialTheme.colors.surface
                )


            }
            val scrollState = rememberScrollState()
            val scope = rememberCoroutineScope()
            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(start = 8.dp, bottom = 8.dp)
                    .horizontalScroll(scrollState)
            ) {
                scope.launch {
                    scrollState.scrollTo(
                        scrollPosition
                    )
                }

                for (category in getAllFoodCategories()) {
                    FoodCategoryChip(
                        category = category.value,
                        isSelected = selectedCategory == category,
                        onSelectedCategoryChanged = {
                            onSelectedCategoryChanged(it)
                            onCategoryChangePosition(
                                getAllFoodCategories().indexOf(selectedCategory)
                            )
                        },
                        onExecuteSearch = {
                            onExecuteSearch()
                        }

                    )
                }
            }
        }
    }
}

您只能使用一种实现中包含的参数组合。例如,您不能将 keyboardOptionsonImeActionPerformed.

一起使用

原来 backgroundColor 属性 不再有效,请使用 colors:。同样正如 Richard Onslow Roper 在他的回答中指出的那样,查看 TextField 的构造函数并查看哪些属性不属于您要使用的 TextField 版本

不做

          TextField(
                    value = query,
                    onValueChange = {
                        onQueryChanged(it)
                    },
                    label = {
                        Text(text = "Search")
                    },
                  
                    backgroundColor = MaterialTheme.colors.surface
                )

改为这样做

          TextField(
                    value = query,
                    onValueChange = {
                        onQueryChanged(it)
                    },
                    label = {
                        Text(text = "Search")
                    },
                  
                    colors=  TextFieldDefaults.textFieldColors(
                        backgroundColor = MaterialTheme.colors.surface
                    )
                )