Andorid Jetpack Compose State not Updating

75 Views Asked by At

I am working on a Jet Shopping App using Room DB with reference from HOODLAB youtube video & my full code is build without error.

Problems:

  1. When I am adding an item to the list, it is not showing.
  2. When I am adding a store, it is not displaying in the dropdown menu.

Github link - https://github.com/its-ks/Shopping_List_app.git

See the screenshot below:

enter image description here

This is the code I use:

Row {
            TextField(
                value = state.store ,
                onValueChange = {
                    if(isNewEnabled) onStoreChange.invoke(it)
                },
            modifier = modifier.weight(1f),
            colors = TextFieldDefaults.textFieldColors(
                unfocusedIndicatorColor = Color.Transparent,
                focusedIndicatorColor = Color.Transparent
            ),
            shape = Shapes.large,
            label = {Text(text = "Store")},
            leadingIcon = {
                Icon(imageVector = Icons.Default.KeyboardArrowDown, contentDescription = null,
                modifier = androidx.compose.ui.Modifier.clickable {
                    onDialogDismissed.invoke(!state.isScreenDialogDismissed)
                })
            })
            if(!state.isScreenDialogDismissed){
                Popup(
                    onDismissRequest = {
                        onDialogDismissed.invoke(!state.isScreenDialogDismissed)
                    }
                ){
                    Surface(modifier = androidx.compose.ui.Modifier.padding(16.dp)) {
                        Column {
                            state.storeList.forEach{
                                Text(text = it.storeName,
                                modifier = androidx.compose.ui.Modifier
                                    .padding(8.dp)
                                    .clickable {
                                        onStoreChange.invoke(it.storeName)
                                        onDialogDismissed(!state.isScreenDialogDismissed)
                                    },
                                )
                            }
                            
                        }

                    }
                }
            }
            TextButton(onClick = {
                isNewEnabled = if (isNewEnabled) {
                    onSaveStore.invoke()
                    !isNewEnabled
                } else {
                    !isNewEnabled
                }
            }) {
                Text(text = if (isNewEnabled) "Save" else "New")
            }


        }
0

There are 0 best solutions below