What are the options for displaying LazyColumn at the click of a button

Viewed 23

it is necessary that by clicking the button an object is added to the list and the added object is displayed in the list

setContent {
            ComposeTheme {
                Column(
                    Modifier
                        .fillMaxSize()
                        .padding(16.dp)
                ) {
                    AddNewEmployee(employee = mEmployee)
                    ShowAllEmployees(list = mListEmployees)
                }
            }
        }

by clicking the button, the object is added, but I do not know how to update the list in runtime

@Composable
    fun FloatingButton(employee: Person) {
        FloatingActionButton(
            onClick = {
                mListEmployees.add(employee)
            }
        ) {

            Icon(
                imageVector = Icons.Default.Add,
                contentDescription = getString(R.string.add_description)
            )
        }
    }

the code that should display the list

@Composable
    fun ShowAllEmployees(list: List<Person>) {
        LazyColumn {
            items(list) { employee ->
                ShowText(employee = employee)
            }
        }
    }

    @Composable
    fun ShowText(employee: Person) {
        Text(
            text = "${employee.Name}, ${employee.Department}",
            fontSize = 16.sp
        )
    }

I hope I wrote it clearly and not confusing)

0 Answers
Related