Cannot compile when move to another compose function

Issue

Hi I don’t know how can I call "weight(1f)" in my another comopose funtion

Error gives me

Expression weight cannot be invoke as a function. The funtcion invokle is not found

FoodMenu

@Composable
fun FoodMenu(modifier: Modifier = Modifier)
{
 Row (modifier=Modifier.fillMaxWidth()
.wrapContentSize()
    )
  {
     FoodItem()
  }
}

FoodItem

@Composable
fun FoodItem(modifier: Modifier = Modifier)
{
   Box(modifier = Modifier.weight(1f))
   {
       Text(text= "Salad")
   }

   Box(modifier = Modifier.weight(1f))
   {
       Text(text= "Salad")
   }

}

Any help please,.thanks so much

Solution

I put Rowscope and it work

@Composable
fun RowScope.FoodItem(modifier: Modifier = Modifier)
{
   Box(
modifier = Modifier.weight(1f)) {
       Text(text= "Salad")
   }

   Box(modifier = Modifier.weight(1f))
   {
       Text(text= "Fries")
   }

Answered By – Shane

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published