gpt4 book ai didi

android - 如何在jetpack compose中通过lambda返回columnScope/RowScope

转载 作者:行者123 更新时间:2023-12-05 01:48:59 24 4
gpt4 key购买 nike

我想知道如何通过jetpack compose中的lamda函数返回Column/Row。我尝试了一些东西,但它给了我错误。

配对内容

@Composable
fun PairContent(
bluetoothEnable: (ColumnScope) -> Unit,
) {
AnimatedVisibility(visible = true) {
Scaffold {
Column { columnScope ->
bluetoothEnable(columnScope)
}
}
}
}

错误

Type mismatch.
Required:
ColumnScope.() → Unit
Found:
ColumnScope.(Any?) → Unit

Cannot infer a type for this parameter. Please specify it explicitly.

图像错误

enter image description here

最佳答案

ColumnScope 应该是参数的接收者bluetoothEnable: ColumnScope.() -> Unit

@Composable
fun PairContent(
bluetoothEnable: @Composable ColumnScope.() -> Unit,
) {
AnimatedVisibility(visible = true) {
Scaffold {
Column {
bluetoothEnable()
}
}
}
}

关于android - 如何在jetpack compose中通过lambda返回columnScope/RowScope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74572329/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com