Im learning programming for the first time in my life, I’ve been around 2 weeks learning Kotlin with a free course, and a week learning Jetpack Compose in Android Studio especifically. I’ve been stuck 2 days with a noobie practice, but every answer I encounter on the internet assumes I know more than I know. The practice consists in making a Quadrant like this CorrectQuadrant but unless I make a change that doesn’t make sense to me I’m only able to get it like this IncorrectQuadrant.
So the thing is I don’t quite understand the modifier parameter, so trying and trying I finally downloaded the solution code and found the mistake, but I cannot understand why is a mistake. In the code below, in the private function "ComposeInfoCard", you can see a modifier Column argument surrounded by (=====). If I write that argument in lowercase (modifier = modifier) I get the correct Quadrant. If I write it like it is (modifier = Modifier), and that’s how I supossed it was correct, the modifier parameter in the private function says "Parameter modifier is never used", and that’s not true because I’m using it 4 times for the weight modifier in the ComposeQuadrant function.
Can someone explain why it needs to be in lowercase, and, if you don’t mind, explain the object modifier like I’m a complete noobie in programming and retarded? Thank you.
@Composable
fun ComposeQuadrant(){
Column (modifier = Modifier.fillMaxWidth()){
Row (modifier = Modifier.weight(1f)){
ComposeInfoCard(
title = stringResource(R.string.title1),
description = stringResource(R.string.description1),
backgroundColor = Color(0xFFEADDFF),
modifier = Modifier.weight(1f)
)
ComposeInfoCard(
title = stringResource(R.string.title2),
description = stringResource(R.string.description2),
backgroundColor = Color(0xFFD0BCFF),
modifier = Modifier.weight(1f)
)
}
Row (Modifier.weight(1f)){
ComposeInfoCard(
title = stringResource(R.string.title3),
description = stringResource(R.string.description3),
backgroundColor = Color(0xFFB69DF8),
modifier = Modifier.weight(1f)
)
ComposeInfoCard(
title = stringResource(R.string.title4),
description = stringResource(R.string.description4),
backgroundColor = Color(0xFFF6EDFF),
modifier = Modifier.weight(1f)
)
}
}
}
@Composable
private fun ComposeInfoCard(
title: String,
description: String,
backgroundColor: Color,
modifier: Modifier = Modifier) {
=========================================================
Column (modifier = Modifier
=========================================================
.padding(16.dp)
.background(backgroundColor)
.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
){
Text(
text = title,
fontWeight = FontWeight.Bold,
modifier = Modifier.padding(bottom = 16.dp)
)
Text(
text = description,
textAlign = TextAlign.Justify
)
}
}
>Solution :
In your ComposeInfoCard function you have a modifier parameter of type Modifier.
Then when you do Column (modifier = modifier
Here you want to use this modifier parameter. If you do Column (modifier = Modifier then, instead of using the Modifier you passed as parameter to the function, you create a new Modifier.
That’s why you get the message saying that the modifier parameter is not used, and that your ComposeInfoCard doesn’t behave as espected.