在代码中使用updateStateToList()函数来更新mutableStateListOf
import androidx.compose.runtime.mutableStateListOf
val list = mutableStateListOf("apple", "banana", "orange")
fun updateStateToList() {
list.add("grape")
list.remove("apple")
}
注意,必须先使用mutableStateListOf()创建可变状态列表,还需确保使用Compose函数(如LaunchedEffect、DisposableEffect、remember等)来更新该列表中的项目。通常情况下,更新列表中的项目会触发重新构建UI。