Class StepFlow

All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class StepFlow extends Container

A multi-step flow: a checkout, a sign-up or a setup wizard. Each step has a title, an optional subtitle and a body; a row of numbered markers shows where the user is, and Back and Continue buttons move between the steps. It is Flutter's Stepper, Material's stepper and the MUI Stepper.

TextField address = new TextField("", "Address");
StepFlow flow = new StepFlow()
        .addStep("Shipping", "Where it goes", address)
        .addStep("Payment", null, new Label("Card on file"))
        .addStep("Review", null, new Label("Everything looks right"));
flow.setStepValidator((f, step) -> step != 0 || address.getText().length() > 0);
flow.addFinishListener(e -> Log.p("Order placed"));
Form form = new Form("Checkout", new BorderLayout());
form.add(BorderLayout.CENTER, flow);
form.show();

Steps before the current one are done and show a check, the current one is filled and later ones are faded. #setError(int, boolean) marks a step as failed and #setStepEnabled(int, boolean) skips it. A validator runs before the user leaves a step forwards; when it refuses, the step is marked as an error and the flow stays where it is. Going back never validates.

By default the markers run across the top and the body of the current step fills the space below them. new StepFlow(true) lays the steps out in a column instead, with the current step's body and buttons opening under its title, the layout Flutter calls a vertical stepper.

For a read-only progress display with no bodies (order tracking, a delivery status) use ActivityTimeline. The numeric Stepper control is unrelated.

UIIDs: StepFlow for the whole component, StepFlowHeader for the row of markers, StepFlowTitle and StepFlowSubtitle for a step's texts, StepFlowContent for the body, StepFlowNavigation for the button bar, StepFlowBackButton and StepFlowNextButton for its buttons. The marker colours follow the theme's Slider colours unless StepFlowMarker is styled; StepFlowMarkerError sets the error colour.

  • Field Details

    • DONE

      public static final int DONE
      The step's position relative to the current one decides how it is drawn: before it is done.
      See Also:
    • CURRENT

      public static final int CURRENT
      The step being shown.
      See Also:
    • PENDING

      public static final int PENDING
      A step after the current one.
      See Also:
    • ERROR

      public static final int ERROR
      A step marked as failed with #setError(int, boolean).
      See Also:
    • DISABLED

      public static final int DISABLED
      A step turned off with #setStepEnabled(int, boolean).
      See Also:
  • Constructor Details

    • StepFlow

      public StepFlow()
      An empty flow with its markers across the top.
    • StepFlow

      public StepFlow(boolean vertical)

      An empty flow.

      Parameters
      • vertical: true to stack the steps in a column, with the current step's body under its title; false for markers across the top
  • Method Details

    • initUnselectedStyle

      protected void initUnselectedStyle(Style unselectedStyle)
      Description copied from class: Component

      Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.

      Parameters
      • unselectedStyle: The unselected style.
      Overrides:
      initUnselectedStyle in class Component
    • isVertical

      public boolean isVertical()

      Whether the steps are stacked in a column.

      Returns

      true for a vertical flow

    • addStep

      public StepFlow addStep(String title, String subtitle, Component content)

      Adds a step at the end. The first step added becomes the current one.

      Parameters
      • title: the step's title

      • subtitle: a short line under the title, or null

      • content: the step's body, or null for a step with no body

      Returns

      this, for chaining

    • clearSteps

      public void clearSteps()
      Removes every step.
    • getStepCount

      public int getStepCount()

      The number of steps.

      Returns

      the step count

    • getCurrentStep

      public int getCurrentStep()

      The index of the step being shown.

      Returns

      the current step, or -1 when the flow is empty

    • setCurrentStep

      public void setCurrentStep(int index)

      Shows a step without running the validator. Use it to restore a flow or to move the user from code; the user's own moves go through #next(), #back() and taps on the markers.

      Parameters
      • index: the step to show
    • getState

      public int getState(int index)

      How a step is drawn now: #DONE, #CURRENT, #PENDING, #ERROR or #DISABLED.

      Parameters
      • index: the step's index
      Returns

      the step's state

    • setError

      public void setError(int index, boolean error)

      Marks a step as failed, or clears the mark. A step the validator refused is marked automatically and cleared when it next passes.

      Parameters
      • index: the step's index

      • error: true to show the step as an error

    • setStepEnabled

      public void setStepEnabled(int index, boolean enabled)

      Turns a step on or off. #next() and #back() skip a disabled step, and a tap on it does nothing.

      Parameters
      • index: the step's index

      • enabled: false to skip the step

    • isStepEnabled

      public boolean isStepEnabled(int index)

      Whether a step is on.

      Parameters
      • index: the step's index
      Returns

      false when the step is skipped

    • getStepContent

      public Component getStepContent(int index)

      The body of a step.

      Parameters
      • index: the step's index
      Returns

      the component passed to #addStep(String, String, Component)

    • setStepValidator

      public void setStepValidator(StepFlow.StepValidator validator)

      Sets the validator that runs before the user moves forwards.

      Parameters
      • validator: the validator, or null to allow every move
    • setTapToJump

      public void setTapToJump(boolean tapToJump)

      Whether a tap on a step's marker or title moves to it. Moving back is always allowed; moving forwards validates every step in between. On by default.

      Parameters
      • tapToJump: false to move only with the buttons
    • isTapToJump

      public boolean isTapToJump()

      Whether taps on the steps move to them.

      Returns

      true when a tap moves to the step

    • setAnimated

      public void setAnimated(boolean animated)

      Whether moving between steps slides the body. On by default.

      Parameters
      • animated: false to switch bodies at once
    • setNavigationVisible

      public void setNavigationVisible(boolean visible)

      Shows or hides the Back and Continue buttons, for a flow driven from the application's own buttons through #next() and #back().

      Parameters
      • visible: false to hide the button bar
    • setButtonTexts

      public void setButtonTexts(String back, String next, String finish)

      Sets the button texts.

      Parameters
      • back: the Back button's text

      • next: the text of the button that moves forwards

      • finish: the text that button shows on the last step

    • getBackButton

      public Button getBackButton()

      The Back button, to restyle it or give it an icon.

      Returns

      the Back button

    • getNextButton

      public Button getNextButton()

      The Continue / Finish button.

      Returns

      the button that moves forwards

    • addStepListener

      public void addStepListener(ActionListener l)

      Listens for the current step changing. The event's source is this flow; read #getCurrentStep().

      Parameters
      • l: the listener
    • removeStepListener

      public void removeStepListener(ActionListener l)

      Removes a step listener.

      Parameters
      • l: the listener
    • addFinishListener

      public void addFinishListener(ActionListener l)

      Listens for the user finishing the flow: Continue pressed on the last step after it validated.

      Parameters
      • l: the listener
    • removeFinishListener

      public void removeFinishListener(ActionListener l)

      Removes a finish listener.

      Parameters
      • l: the listener
    • next

      public boolean next()

      Moves to the next enabled step after validating the current one. On the last step it validates and then notifies the finish listeners.

      Returns

      true if the flow moved on or finished

    • back

      public boolean back()

      Moves to the previous enabled step, without validating.

      Returns

      false when there is no earlier step