android 如何在jetpack合成中通过lambda返回columnScope/RowScope

nue99wik  于 2022-11-27  发布在  Android
关注(0)|答案(1)|浏览(131)

我想知道如何通过jetpack compose中的lambda函数返回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.

图像中有错误

zi8p0yeb

zi8p0yeb1#

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

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

相关问题