类型不匹配。必需:( paddingvalues)→发现单位:单位
我正在尝试使用以下位置显示一个配置文件屏幕:
Scaffold(
topBar = {
DarkTopBar()
},
content = ProfileContent()
)
ProfileContent()
看起来像这样:
@Composable
fun ProfileContent() {
Box(
modifier = Modifier.fillMaxSize().padding(top = 96.dp),
contentAlignment = Alignment.TopCenter
) {
Text(
text = "Good day!",
fontSize = 48.sp
)
}
}
但是我会收到以下错误:
类型不匹配:推断类型是单位,但(paddingvalues) - >预计单位
我试图解决此问题的单位是将上述功能调用在体内:
Scaffold(
topBar = {
DarkTopBar()
}
) {
ProfileContent() //Moved here.
}
但是Android Studio抱怨说:
内容填充参数不使用
任何人可以帮助我吗?
I'm trying to display a profile screen using:
Scaffold(
topBar = {
DarkTopBar()
},
content = ProfileContent()
)
Where the ProfileContent()
looks like this:
@Composable
fun ProfileContent() {
Box(
modifier = Modifier.fillMaxSize().padding(top = 96.dp),
contentAlignment = Alignment.TopCenter
) {
Text(
text = "Good day!",
fontSize = 48.sp
)
}
}
But I get the following error:
Type mismatch: inferred type is Unit but (PaddingValues) -> Unit was expected
What I have tried to solve this problem is to move the above function call inside the body:
Scaffold(
topBar = {
DarkTopBar()
}
) {
ProfileContent() //Moved here.
}
But Android Studio is complaining saying:
Content padding parameter it is not used
Can anyone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是
content
脚手架的参数
应采用可合算功能。在这里,您不是像您认为自己一样将函数作为参数传递,而是实际上调用了该功能。要修复,将函数调用放入lambda中的content
,就像topappbar
一样。因此,请更改:
对此:
Your problem is that the
content
parameter ofScaffold
should take a composable function. Here, you are not passing the function as an argument as you think you are, but instead actually calling the function. To fix put the function call inside a lambda forcontent
like you did fortopAppBar
.So change this:
To this: