https://kotlinlang.org logo
#android
Title
# android
f

Flammer99

04/01/2024, 3:27 PM
Copy code
@Composable
fun list(
    item: GymContents,
    onEditClick: @Composable () -> Unit,
    onDeleteClick: () -> Unit,
    viewModel: GymViewModel
) {
    val isEditing by viewModel.isEditing.collectAsState()
    Row(
        modifier = Modifier
            .padding(8.dp)
            .fillMaxWidth()
            .border(
                border = BorderStroke(2.dp, Color.Black),
                shape = RoundedCornerShape(20)
            )
    ) {
        Text(text = item.name, modifier = Modifier.padding(8.dp))
        Text(
            text = "Sets: ${item.sets}",
            modifier = Modifier.padding(8.dp)
        )
        Text(text = "Reps: ${item.reps}")
        Text(text = "Lift: ${item.lift}")
        Row(modifier = Modifier.padding(8.dp)) {
            IconButton(onClick = onEditClick) {
                Icon(imageVector = Icons.Default.Edit, contentDescription = null)
            }

            IconButton(onClick = onDeleteClick) {
                Icon(imageVector = Icons.Default.Delete, contentDescription = null)
            }

        }
    }}
Type inference failed. Expected type mismatch: inferred type is @Composable () -> Unit but () -> Unit was expected
c

Chrimaeon

04/01/2024, 3:35 PM
You defined
onEditClick
as a Composable function. But
onClick
expects a “normal” function.
f

Flammer99

04/01/2024, 3:41 PM
mh
so what do u think i should go for?
Also you might get better infos of you ask questions about compose in #compose-android
f

Flammer99

04/01/2024, 3:43 PM
okk
j

Julien Raad

04/01/2024, 4:30 PM
On edit click cannot be compostable. You need to manage showing/hiding the dialog via a state. To do that onEditClick should just change that state from false to true. Something like var isDialogVisible by rememberSaveable { mutableStateOf(false) } then onEditClick = { isDialogVisible = true } In your compose code, do if (isDialogVisible) { EditDialog() // that's the composable function }
f

Flammer99

04/01/2024, 4:37 PM
done it, but in this way i think that the edit function is not called
c

Chrimaeon

04/01/2024, 5:53 PM