Hi guys can someone help me to make these buttons ...
# compose
f
Hi guys can someone help me to make these buttons work?(they should show another page where i can add the food name etc)
the function isAddingPage is not used:
Copy code
@SuppressLint("StateFlowValueCalledInComposition")
@Composable
fun isAddingPage(homeViewModel: homeViewModel,
                 FoodViewModel: FoodViewModel,
                 IsAddingViewModel: IsAddingViewModel,
                 food: FoodStatistics,
){
    val isAdding by FoodViewModel.foodStatisticsLiveData.collectAsState()
    if(isAdding.listSnacks.isChosen) {
        Column {
            Column {
                Row {
                    Text(text = "{${IsAddingViewModel.isAddingName.value}}")
                }
                Row {
                    Button(onClick = { /*TODO*/ }) {
                        Icon(Icons.Default.Search, contentDescription = "")

                    }
                }
                Row {
                    Button(onClick = { /*TODO*/ }) {
                        Icon(Icons.Default.Star, contentDescription = "P.H")

                    }
                }
            }
            listFood()
        }
    }
    else if(isAdding.listLunch.isChosen) {
        Column(modifier = Modifier.fillMaxSize()) {
            Column {
                Row {
                    Text(text = "{${IsAddingViewModel.isAddingName.value}}")
                }
                Row {
                    Button(onClick = { /*TODO*/ }) {
                        Icon(Icons.Default.Search, contentDescription = "")

                    }
                }
                Row {
                    Button(onClick = { /*TODO*/ }) {
                        Icon(Icons.Default.Star, contentDescription = "P.H")

                    }
                }
            }
            listFood()
        }
    }
    else if(isAdding.listBreakfast.isChosen) {
        Column(modifier = Modifier.fillMaxSize()) {
            Column {
                Row {
                    Text(text = "{${IsAddingViewModel.isAddingName.value}}")
                }
                Row {
                    Button(onClick = { /*TODO*/ }) {
                        Icon(Icons.Default.Search, contentDescription = "")

                    }
                }
                Row {
                    Button(onClick = { /*TODO*/ }) {
                        Icon(Icons.Default.Star, contentDescription = "P.H")

                    }
                }
            }
            listFood()
        }
    }
    else if(isAdding.listDinner.isChosen) {
        Column(modifier = Modifier.fillMaxSize()) {
            Column {
                Row {
                    Text(text = "{${IsAddingViewModel.isAddingName.value}}")
                }
                Row {
                    Button(onClick = { /*TODO*/ }) {
                        Icon(Icons.Default.Search, contentDescription = "")

                    }
                }
                Row {
                    Button(onClick = { /*TODO*/ }) {
                        Icon(Icons.Default.Star, contentDescription = "P.H")

                    }
                }
            }
            listFood()
        }
    }
}
Copy code
class IsAddingViewModel(food: FoodStatistics) {
    private var _isAddingName: MutableStateFlow<String> = MutableStateFlow("")
    var isAddingName: MutableStateFlow<String> = _isAddingName

    fun checkWhat(food: FoodStatistics) {
        _isAddingName.value = when {
            food.listBreakfast.isChosen -> "Breakfast"
            food.listDinner.isChosen -> "Dinner"
            food.listLunch.isChosen -> "Lunch"
            food.listSnacks.isChosen -> "Snacks"
            else -> ""
        }
    }
}
Copy code
@SuppressLint("StateFlowValueCalledInComposition")
@Composable
fun homeLogic(
    viewModel: homeViewModel,
    FoodStatistics:FoodStatistics,
   FoodViewModel: FoodViewModel) {
    val isAdding by FoodViewModel.foodStatisticsLiveData.collectAsState()
Column(Modifier.fillMaxSize()) {
    Row() {
        Column {
            Button(onClick = {
                isAdding.listBreakfast.isChosen = true
            }) {
                Text(text = "Add Breakfast")
            }
        }
        Column {
            Button(onClick = { isAdding.listLunch.isChosen = true }) {
                Text(text = "Add Lunch")
            }

        }
    }
    Row {
        Column {
            Button(onClick = { isAdding.listDinner.isChosen = true }) {
                Text(text = "Add Dinner")

            }

        }
        Column {
            Button(onClick = { isAdding.listSnacks.isChosen = true }) {
                Text(text = "Add Snacks")

            }
        }

    }
}
}
c
Keyword: navigation library. There are couple out there depending on which platform you target and how your architecture looks like. You can search in this channel to get some more information.
f
mh so u recomment something like navhost
am i right?
c
Right direction, yes. 👍🏻
f
mhh
tho idk if is right to use since would be more code, so i thought to use the same "box to show the details to add" so i used:
Copy code
Column {
        Column {
            Row {
                Text(text = "{${IsAddingViewModel.isAddingName.value}}")
            }
            Row {
                Button(onClick = { /*TODO*/ }) {
                    Icon(Icons.Default.Search, contentDescription = "")

                }
            }
            Row {
                Button(onClick = { /*TODO*/ }) {
                    Icon(Icons.Default.Star, contentDescription = "P.H")

                }
                Row {
                    Button(onClick = { }) {
                        Icon(Icons.Default.Delete, contentDescription = "P.H")

                    }
            }
        }
        listFood()
    }
}}
Copy code
fun checkWhat(food: FoodStatistics) {
        _isAddingName.value = when {
            food.listBreakfast.isChosen -> "Breakfast"
            food.listDinner.isChosen -> "Dinner"
            food.listLunch.isChosen -> "Lunch"
            food.listSnacks.isChosen -> "Snacks"
            else -> ""
        }
    }
}
c
Yeah, take what I said or try “fixing” it the way you have it. More code does not always mean more complicated.
f
understood