Vivek Modi
Vivek Modi

Reputation: 7271

How to return columnScope/RowScope through lambda in jetpack compose

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

Upvotes: 2

Views: 1915

Answers (1)

Thracian
Thracian

Reputation: 67189

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

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

Upvotes: 5

Related Questions