我对MyApp函数有一个问题,content值是未解决的,ContactContent()显示了以下错误:@Composable invocations can only happen from the context of a @Composable function
@Composable
fun MyApp(navigateToProfile: (Contact) -> Unit){
Scaffold {
content = {
ContactContent(navigateToProfile = navigateToProfile)
}
}
}ContactContent片段
@Composable
fun ContactContent(navigateToProfile: (Contact) -> Unit) {
val contacts = remember { DataProvider.contactList }
LazyColumn(
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp),
) {
items(
items = contacts,
itemContent = {
ContactListItem(contact = it, navigateToProfile)
}
)
}
}发布于 2021-09-02 12:34:40
你已经进入了Scaffold的身体。你不需要使用content = {}。
改为:
@Composable
fun MyApp(navigateToProfile: (Contact) -> Unit){
Scaffold {
ContactContent(navigateToProfile = navigateToProfile)
}
}content是Scaffold的一个参数,如果您想使用它:
@Composable
fun MyApp(navigateToProfile: (Contact) -> Unit){
Scaffold(
content = {
ContactContent(navigateToProfile = navigateToProfile)
}
)
}两人的工作方式是一样的。
https://stackoverflow.com/questions/69028418
复制相似问题