Home > Net >  JETPACK COMPOSE "Cannot find parameter with this name: contentAlignment"
JETPACK COMPOSE "Cannot find parameter with this name: contentAlignment"

Time:06-27

enter image description here

Am i missing an import or something? Why is this basic function giving me errors all of a sudden

CodePudding user response:

No, you didn't miss anything.

You need only to add your content parameter, and your alignment parameter would be normal.

Example:

Box(modifier = Modifier,
            contentAlignment = Alignment.TopStart,
            content = {}
            )

CodePudding user response:

It happens because exists a Box constructor with no content as in your example code:

@Composable
fun Box(modifier: Modifier): Unit

The contentAlignment doesn't exist in this constructor.

You can use the constructor:

@Composable
inline fun Box(
    modifier: Modifier = Modifier,
    contentAlignment: Alignment = Alignment.TopStart,
    propagateMinConstraints: Boolean = false,
    content: @Composable @ExtensionFunctionType BoxScope.() -> Unit
): Unit

For example:

Box(
    modifier = Modifier,
    contentAlignment = Alignment.Center
){
    //content
}
  • Related