我想用硬编码数据制作简单的30天应用程序,但我有代表当天的变量,我想增加它,但当我这样做时,它做得不太正确.
@Composable
fun _30DaysApp() {
var curDay by remember { mutableStateOf(1) }
Scaffold(topBar = {
}) { it ->
LazyColumn(contentPadding = it) {
items(tasks) {
CardTask(task = it, day = curDay)
curDay++
}
}
}
}
@Composable
fun CardTask(task: Task, day: Int, modifier: Modifier = Modifier) {
var expand by remember { mutableStateOf(false) }
Card(shape = RoundedCornerShape(16.dp)) {
Column(
modifier = modifier
.padding(12.dp)
) {
Row {
Text(text = stringResource(R.string.day, day))
Spacer(modifier = modifier.weight(1f))
ExpandButton(expanded = expand, onClick = { expand = !expand })
}
Text(text = stringResource(task.articleRes))
Spacer(modifier = Modifier.size(8.dp))
Image(
painter = painterResource(task.imageRes), contentDescription = null,
contentScale = ContentScale.Fit
)
}
}
}
试图将其提升到CardTask功能,但仍然不起作用.有人能帮助我吗?