Kotlin: Why am I getting a compile error cannot find a parameter for modifier and contentScale?

331 Views Asked by At

I am getting the error messages "Cannot find a parameter with this name: modifier" and "Cannot find a parameter with this name: contentScale". The compiler is not giving me an option to import anything when I hover on the parameters. How can I resolve this?

@Composable
fun BirthdayGreetingWithImage(message: String, from: String) {
    val image = painterResource(
    id = R.drawable.androidparty,
    modifier = Modifier.fillMaxHeight().fillMaxWidth(),
    contentScale = ContentScale.Crop
)
1

There are 1 best solutions below

0
Ivo On BEST ANSWER

modifier and contentScale needs to be used on an image, not on the painterResource itself. Try

Image(
    painterResource(R.drawable.androidparty),
    modifier = Modifier.fillMaxHeight().fillMaxWidth(),
    contentScale = ContentScale.Crop
)