<div class='sourceset sourceset-android'>Android</div>

```kotlin
public class StackState(@IntRange(from = 0) initialTopItem: Int = 0) : ScrollableState
```

The [VerticalStack](/jetpack-compose/androidx.xr.glimmer/glimmer/components/VerticalStack) state that allows programmatic control and observation of the stack's state.

A [StackState](/jetpack-compose/androidx.xr.glimmer/glimmer/classes/StackState) object can be created and remembered using [rememberStackState](/jetpack-compose/androidx.xr.glimmer/glimmer/composable-functions/rememberStackState).

Note: Properties of the state will only be correctly populated after the [VerticalStack](/jetpack-compose/androidx.xr.glimmer/glimmer/components/VerticalStack) it is
associated with has been composed for the first time.

Warning: A single [StackState](/jetpack-compose/androidx.xr.glimmer/glimmer/classes/StackState) instance must not be shared across multiple [VerticalStack](/jetpack-compose/androidx.xr.glimmer/glimmer/components/VerticalStack)
composables.

#### Parameters

| | |
| --- | --- |
| initialTopItem | The index of the item to show at the top of the stack initially. Must be non-negative. Defaults to 0. |

## Functions

<h2 id="scrolltoitem-item">scrollToItem</h2>

```kotlin
public suspend fun scrollToItem(item: Int)
```

Scroll (jump immediately) to a given [item](/jetpack-compose/androidx.compose.foundation/foundation/functions/item) index.

#### Parameters

| | |
| --- | --- |
| item | The index of the destination item |

<hr class="docs-overload-divider">

<h2 id="animatescrolltoitem-item-animationspec">animateScrollToItem</h2>

```kotlin
public suspend fun animateScrollToItem(
        item: Int,
        animationSpec: AnimationSpec<Float> = spring(),
    )
```

Scroll animate to a given [item](/jetpack-compose/androidx.compose.foundation/foundation/functions/item)'s closest snap position. If the [item](/jetpack-compose/androidx.compose.foundation/foundation/functions/item) is too far away from
`topItem`, not all the items in the range will be composed. Instead, the stack will jump to a
nearer item, then compose and animate the rest of the items until the destination [item](/jetpack-compose/androidx.compose.foundation/foundation/functions/item).

#### Parameters

| | |
| --- | --- |
| item | The index of the destination item |
| animationSpec | An [AnimationSpec](/jetpack-compose/androidx.compose.animation/animation-core/interfaces/AnimationSpec) to move between items |

## Companion Object

#### Properties

<div class='sourceset sourceset-android'>Android</div>

```kotlin
public val Saver: Saver<StackState, *>
```

The default [Saver](/jetpack-compose/androidx.compose.runtime/runtime-saveable/interfaces/Saver) implementation for [StackState](/jetpack-compose/androidx.xr.glimmer/glimmer/classes/StackState).