Unresolved reference with Modifier methods in Jetpack compose

Viewed 6051

I'm learning Jetpack Compose and I was trying to customize a display of an image with Modifier methods height and padding. But I got the Problem messages "Unresolved reference: height" and "Unresolved reference: padding".

@Preview
@Composable
fun imageDisplay() {
    Column(
        modifier = Modifier.padding(16.dp)
    ) {
        Image(
            painter = painterResource(R.drawable.photo_1505740420928_5e560c06d30e),
            contentDescription = null,
            modifier = Modifier
                .height(180.dp)
                .fillMaxWidth()
                .clip(shape = RoundedCornerShape(4.dp)),
            contentScale = ContentScale.Crop

        )

    }

}

padding and height methods highlighted in red

Am I missing something?

4 Answers

Everything looks fine. Make sure you're using the newest version of Android Studio, gradle and compose versions.

  • Android Studio Dolphin | 2021.3.1 Canary 5
  • Compose Version 1.2.0-alpha05
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.material:material-ripple:$compose_version"

And finally, check if you imported the correct Modifier class. You must use the one from androidx.compose.ui package.

Make sure that the package import is correct. Sometimes we accidently import the wrong package for the Modifier function

Use the correct package.

import androidx.compose.ui.Modifier

Updating your Compose and Kotlin plugin version in the project level gradle files would fix it. If that does not work then try syncing project with gradle files.

Wrapping my Column composable in a Row composable made modifier = Modifier.weight(1f) work.

Related