Home > database >  How to return columnScope/RowScope through lamda in jetpack compose
How to return columnScope/RowScope through lamda in jetpack compose

Time:11-25

I want to know how can we return Column/Row through lamda function in jetpack compose. I tried something but it giving me error.

PairContent

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

Error

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

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

Error in image

enter image description here

CodePudding user response:

ColumnScope should be receiver of your parameter bluetoothEnable: ColumnScope.() -> Unit

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