rememberTimePickerState

fun rememberTimePickerState(initialHour: Int, initialMinute: Int, initialPeriod: TimePeriod = if (initialHour >= 12) TimePeriod.PM else TimePeriod.AM, timeFormat: TimeFormat = TimeFormat.HOUR_24): TimePickerState

Creates and remembers a TimePickerState. Initial time values are read when the state is first created.

Return

A TimePickerState initialized with the given time values.

Parameters

initialHour

The initial hour to be selected. If timeFormat is TimeFormat.HOUR_12, this value is automatically adjusted to the 12-hour format (1-12).

initialMinute

The initial minute to be selected.

initialPeriod

The initial period (AM/PM) to be selected. Defaults to the current period based on the current hour.

timeFormat

The time format (12-hour or 24-hour). Defaults to TimeFormat.HOUR_24.


fun rememberTimePickerState(initialTime: LocalTime = currentDateTime().time, timeFormat: TimeFormat = TimeFormat.HOUR_24): TimePickerState

Creates and remembers a TimePickerState from a LocalTime.

When timeFormat is TimeFormat.HOUR_12, the hour is converted to the format-hour range (1-12) and the AM/PM period is derived from initialTime.

Return

A TimePickerState initialized from initialTime.

Parameters

initialTime

The initial time to be selected.

timeFormat

The time format (12-hour or 24-hour). Defaults to TimeFormat.HOUR_24.


fun rememberTimePickerState(items: TimePickerItems, initialTime: LocalTime = currentDateTime().time, timeFormat: TimeFormat = TimeFormat.HOUR_24): TimePickerState

Creates and remembers a TimePickerState whose initial value is coerced by items.

Initial values and items are read when the state is first created. An items-only recomposition does not reset the state. If timeFormat changes, the state is recreated against the latest items. On recreation, the items supplied by the recreated composition also coerce the saved value, so the picker cannot restore outside its current custom lists or time bounds.

Return

A TimePickerState initialized to the closest selectable time.

Parameters

items

Selectable values used to coerce initialTime before creating the state.

initialTime

The requested initial time.

timeFormat

The time format (12-hour or 24-hour). Defaults to TimeFormat.HOUR_24.

Throws

if the item lists needed by timeFormat are invalid or contain no time allowed by their constraints.


fun rememberTimePickerState(items: TimePickerItems, initialHour: Int, initialMinute: Int, initialPeriod: TimePeriod = if (initialHour >= 12) TimePeriod.PM else TimePeriod.AM, timeFormat: TimeFormat = TimeFormat.HOUR_24): TimePickerState

Creates and remembers a TimePickerState whose explicit initial time parts are coerced by items.

Initial values and items are read when the state is first created. initialHour is interpreted the same way as rememberTimePickerState without items: as an hour-of-day in 0..23, then converted to the active timeFormat. In 12-hour mode, initialPeriod can override the period derived from initialHour. On recreation, the items supplied by the recreated composition also coerce the saved value.

Return

A TimePickerState initialized to the closest selectable time.

Parameters

items

Selectable values used to coerce initialHour and initialMinute.

initialHour

The requested initial hour-of-day. Must be in 0..23.

initialMinute

The requested initial minute. Must be in 0..59.

initialPeriod

The requested AM/PM period when timeFormat is TimeFormat.HOUR_12.

timeFormat

The time format (12-hour or 24-hour). Defaults to TimeFormat.HOUR_24.

Throws

if initialHour or initialMinute is outside its supported range, or if the item lists needed by timeFormat are invalid or contain no time allowed by their constraints.