Skip to content

Wizard

@Composable



fun Wizard(
    pages: List<WizardPage>, 
    state: WizardState = rememberWizardState(), 
    modifier: Modifier = Modifier, 
    contentWidth: Int = DEFAULT_CONTENT_WIDTH, 
    contentHeight: Int? = null, 
    backText: Component = Component.literal("Back"), 
    cancelText: Component = Component.literal("Cancel"), 
    nextText: Component = Component.literal("Next"), 
    finishText: Component = Component.literal("Finish"), 
    transitionSpec: AnimationSpec = DEFAULT_SLIDE_SPEC, 
    onCancel: () -> Unit = {}, 
    onFinish: () -> Unit = {}
)

A multi-page dialog body: one page at a time, with Back/Cancel/forward navigation, a horizontal slide between pages, and per-page validation gating the forward button.

Suited to a flow whose later steps depend on earlier answers - asking for a quantity, then showing what that quantity actually entails and letting the reader commit or go back and change it. A single scrolling form is the better shape when the steps are independent.

The forward button reads nextText on every page but the last, where it becomes finishText and runs onFinish; either can be overridden per page via WizardPage.forwardText. It is disabled while the current page reports WizardValidation.Blocked, whose reason is shown beneath the page.

Parameters

  • pages: The steps, in order. Rendering nothing is the correct response to an empty list.

  • contentHeight: Fixes the viewport height. Left null, the wizard is as tall as its current page, so the frame resizes as pages change; worth setting when the pages differ a lot in height.

  • onCancel: Invoked by the Cancel button. Dismissing the containing modal is the caller's to do.

  • onFinish: Invoked by the forward button on the last page, only while that page validates.

@Composable



fun Wizard(
    modifier: Modifier = Modifier, 
    state: WizardState? = null, 
    contentWidth: Int = DEFAULT_CONTENT_WIDTH, 
    contentHeight: Int? = null, 
    backText: Component = Component.literal("Back"), 
    cancelText: Component = Component.literal("Cancel"), 
    nextText: Component = Component.literal("Next"), 
    finishText: Component = Component.literal("Finish"), 
    transitionSpec: AnimationSpec = DEFAULT_SLIDE_SPEC, 
    onCancel: () -> Unit = {}, 
    onFinish: () -> Unit = {}, 
    builder: WizardScope.() -> Unit
)

DSL overload declaring pages inline via WizardScope.page rather than building a list.

Parameters

  • builder: Declares the pages, in order.