'How to show DropdownMenu as dialog

Is it possible to show items in a DropdownMenu as a Dialog rather than a traditional Spinner? I noticed that the former is much better at handling and display a bigger set of items.

Expected result

enter image description here

Current code

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyAppTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colors.background
                ) {
                    VerticalScrollView()
                }
            }
        }
    }
}

@Composable
fun VerticalScrollView() {
    val list = listOf(
        stringResource(R.string.item_1),
        stringResource(R.string.item_2),
        stringResource(R.string.item_3))
    val expanded = remember{ mutableStateOf(false)}
    val currentValue = remember{ mutableStateOf(listP[0])}

    Column (
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp)
    ) {
            Row {
                Text(stringResource(R.string.property_type_asterisk),
                    style = MaterialTheme.typography.subtitle1,
                    modifier = Modifier.padding(0.dp, 0.dp, 0.dp, 0.dp))
            }

            Row(modifier = Modifier.clickable {
                expandedP.value = !expandedP.value
            }) {
                Text(text = currentValueP.value)
                Icon(imageVector = Icons.Filled.ArrowDropDown, contentDescription = null)

                DropdownMenu(expanded = expandedP.value, onDismissRequest = {
                    expandedP.value = false
                }) {
                    listP.forEach {
                        DropdownMenuItem(onClick = {
                            currentValueP.value = it
                            expandedP.value = false
                        }) {
                            Text(text = it)
                        }
                    }
                }
            }
        }
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source