【发布时间】:2021-11-09 20:50:33
【问题描述】:
在我的 OpinionViewModel 中:
val labels = MutableStateFlow<MutableList<String>>(mutableListOf())
当操作来自 UI(来自 BottomSheet 项目)时,我将项目添加到我的列表中:
state.labels.value.add("Lorem Ipsu")
我的主要@Composable:
fun OpinionScreen(viewModel: OpinionViewModel) {
val scrollState = rememberScrollState()
val bottomState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
val items by viewModel.state.labels.collectAsState()
AppTheme(isSystemInDarkTheme()) {
ModalBottomSheetLayout(
sheetState = bottomState,
sheetContent = { AddPhotoBottomSheet()}) {
Scaffold(
topBar = { TopBar()},
content = {
Box(
modifier = Modifier.fillMaxSize()
) {
Column(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.verticalScroll(scrollState)
) {
FirstSection()
HowLongUsageSection(photos)
ThirdSection()
}
}
})
}
}
}
@Composable 部分:
fun HowLongUsageSection(labels: MutableList<String>) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(top = 10.dp, start = 10.dp, end = 10.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
labels.forEach {
Text(text = it, color = Color.Blue)
}
}
问题是没有重组发生。我需要返回并再次打开 UI 以查看添加的项目。我是否遗漏了什么或问题与底页有关?
【问题讨论】:
标签: android kotlin android-jetpack-compose