'Unresolved reference with Modifier methods in Jetpack compose

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?



Solution 1:[1]

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.

Solution 2:[2]

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

Solution 3:[3]

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.

Solution 4:[4]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Muhammad A R
Solution 3 Rawlin Crasto
Solution 4 user18927078