Hi guys, What approach are you using for use a va...
# compose
f
Hi guys, What approach are you using for use a value of the child in the parent composable? ViewModel, sent callback to child ¿Alternatives plz? Sample Code: I need selected item of child composable in the parent.
Copy code
@Composable
fun SearchFile(viewModel: SearchFileModel) {
  val onclick : (Path) -> () -> Unit =  {// Ugly callback - Provisional Solution
    {
      openFile(it)
      focusRequester.requestFocus()
    }
  }

  if (stateUI.isFoundFiles)
      filesCard(stateUI.files, onclick) // Composable List
}

@Composable
fun filesCard(files: List<Directory> = listOf(), onclick: (Path) -> () -> Unit ) {
    Card (modifier = Modifier.fillMaxHeight(0.9f).fillMaxWidth()) {
        LazyColumn(modifier = Modifier.fillMaxHeight()) {
            items(files) {file ->
                Card(
                    backgroundColor = Color(245, 238, 254),
                    shape = RoundedCornerShape(8.dp),
                    modifier = Modifier.padding(vertical = 4.dp, horizontal = 4.dp),
                    onClick = onclick(file.path)
                ) { ...... }
            }
        }
    }
}