Skip to content

CountryPickerDialog

K M Rejowan Ahmmed edited this page May 13, 2024 · 2 revisions

CountryPickerDialog

This is Dialog Composable. It will return the selected country when an item is clicked. It doesn't have an ui that can be added as a composable (you can do that, but it's not recommended).

Basic Usage

        var country by remember { mutableStateOf(selectedCountry) }
        var isPickerOpen by remember { mutableStateOf(false) }

        CountryPickerDialog(
            modifier = Modifier.clip(shape = RoundedCornerShape(10.dp)),
            onDismissRequest = { isPickerOpen = false },
            onItemClicked = {
                country = it
                isPickerOpen = false

            },
            textStyle = textStyle,
            listOfCountry = countryList,
            pickerCustomization = pickerCustomization,
            itemPadding = itemPadding,
            backgroundColor = backgroundColor
        )

Demo

Shot2

Constructor

@Composable
fun CountryPickerDialog(
    modifier: Modifier = Modifier,
    onDismissRequest: () -> Unit,
    onItemClicked: (item: Country) -> Unit,
    textStyle: TextStyle = TextStyle(),
    listOfCountry: List<Country>,
    pickerCustomization: PickerCustomization = PickerCustomization(),
    itemPadding: Int = 10,
    backgroundColor: Color = MaterialTheme.colorScheme.surface,
)

Others

You can learn about the pickerCustomization from the Utils