var courses by rememberSaveable { mutableStateOf(mutableListOf<String>()) }
val physiotherapy = stringResource(R.string.physiotherapy)
val chemotherapy = stringResource(R.string.chemotherapy)
val biology = stringResource(R.string.biology)
val political = stringResource(R.string.political)
val history = stringResource(R.string.history)
val geography = stringResource(R.string.geography)
val courseList = listOf(physiotherapy, chemotherapy, biology, political, history, geography)
courseList.forEachIndexed { _, s ->
FilterChip(
selected = s in courses,
leadingIcon = {
AnimatedVisibility(visible = s in courses) {
Icon(
imageVector = Icons.Rounded.Done,
contentDescription = stringResource(R.string.selected)
)
}
},
onClick = {
courses.apply {
if (s in this) {
remove(s)
} else {
add(s)
}
}
},
label = { Text(text = s) }
)
}
这是我使用 Jetpack Compose 所写的一段代码,这段代码在一个弹窗里,就是一个高中生选科的功能,但是 FilterChip 被点击后,不会实时更新,只有在再次打开弹窗后才会生效,求解