DialogList

fun <T> DialogList(state: BaseDialogState, items: List<T>, key: (item: T) -> Int, content: @Composable (item: T, context: DialogList.ItemContext) -> Unit, selectionMode: DialogList.SelectionMode<T>, divider: @Composable () -> Unit? = null, description: String = "", filter: DialogList.Filter<T>? = null, title: @Composable () -> Unit? = null, icon: @Composable () -> Unit? = null, style: ComposeDialogStyle = DialogDefaults.defaultDialogStyle(), buttons: DialogButtons = DialogDefaults.buttons(), options: DialogOptions = DialogDefaults.options(), onEvent: (event: DialogEvent) -> Unit = {})

Displays a dialog containing a selectable or clickable list of items.

This overload is intended for already available item lists.

Each item is identified by key. The key is also used by selectionMode to determine and update the selected item state.

The content slot receives the item and an DialogList.ItemContext. Custom item implementations should use the context to read the current selection state and call DialogList.ItemContext.performItemAction whenever the item is activated by the user.

Parameters

state

Controls the visibility and lifecycle of the dialog.

items

The items displayed in the dialog.

key

Returns a stable unique identifier for an item. The identifier is also used internally for selection handling.

content

Composable used to render an item. Receives both the item and its associated DialogList.ItemContext.

selectionMode

Defines how item interactions and selection are handled.

divider

Optional divider displayed between list items. By default, no dividers are shown.

description

Optional text displayed above the list content.

filter

Optional filter configuration used to filter visible items.

title

Optional dialog title.

icon

Optional dialog icon displayed next to the title.

style

Defines the visual appearance of the dialog.

buttons

Defines the dialog buttons.

options

Additional dialog configuration options.

onEvent

Callback invoked for dialog events.

Example:

DialogList(
state = state,
items = users,
key = { it.id },
selectionMode = DialogList.SelectionMode.MultiSelect(
selected = selectedUserIds
),
content = DialogListDefaults.itemContent(
text = { Text(it.name) },
supportingText = { Text(it.email) }
),
title = {
Text("Select users")
}
)

fun <T> DialogList(state: BaseDialogState, items: suspend () -> List<T>, key: (item: T) -> Int, content: @Composable (item: T, context: DialogList.ItemContext) -> Unit, selectionMode: DialogList.SelectionMode<T>, itemSaver: Saver<MutableState<List<T>>, out Any>? = null, loadingIndicator: @Composable () -> Unit = { Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { CircularProgressIndicator() } }, divider: @Composable () -> Unit? = null, description: String = "", filter: DialogList.Filter<T>? = null, title: @Composable () -> Unit? = null, icon: @Composable () -> Unit? = null, style: ComposeDialogStyle = DialogDefaults.defaultDialogStyle(), buttons: DialogButtons = DialogDefaults.buttons(), options: DialogOptions = DialogDefaults.options(), onEvent: (event: DialogEvent) -> Unit = {})

Displays a dialog containing a selectable or clickable list of items loaded asynchronously.

This overload is useful when the list content has to be loaded when the dialog is shown. Until loading is complete, loadingIndicator is displayed.

If itemSaver is provided, the loaded items are stored using rememberSaveable. This can be useful when the dialog should preserve loaded data across configuration changes or process recreation.

Each item is identified by key. The key is also used by selectionMode to determine and update the selected item state.

The content slot receives the item and an DialogList.ItemContext. Custom item implementations should use the context to read the current selection state and call DialogList.ItemContext.performItemAction whenever the item is activated by the user.

Parameters

state

Controls the visibility and lifecycle of the dialog.

items

Suspended function used to load the items displayed in the dialog.

key

Returns a stable unique identifier for an item. The identifier is also used internally for selection handling.

content

Composable used to render an item. Receives both the item and its associated DialogList.ItemContext.

selectionMode

Defines how item interactions and selection are handled.

itemSaver

Optional saver used to persist loaded items across state restoration.

loadingIndicator

Composable displayed while items are being loaded.

divider

Optional divider displayed between list items. By default, no dividers are shown.

description

Optional text displayed above the list content.

filter

Optional filter configuration used to filter visible items.

title

Optional dialog title.

icon

Optional dialog icon displayed next to the title.

style

Defines the visual appearance of the dialog.

buttons

Defines the dialog buttons.

options

Additional dialog configuration options.

onEvent

Callback invoked for dialog events.

Example:

DialogList(
state = state,
items = {
repository.loadUsers()
},
key = { it.id },
selectionMode = DialogList.SelectionMode.SingleSelect(
selected = selectedUserId
),
content = DialogListDefaults.itemContent(
text = { Text(it.name) },
supportingText = { Text(it.email) }
),
title = {
Text("Select user")
}
)